Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Typing][B-93] Add type annotations for python/paddle/reader/decorator.py #66305

Merged
merged 2 commits into from
Jul 22, 2024

Conversation

SigureMo
Copy link
Member

PR Category

User Experience

PR Types

Improvements

Description

python/paddle/reader/decorator.py 标注类型,不过对于一些 map、compose 这种用法,现在 Python 类型提示还没有一个比较好的解决方案,就连 map 的实现都只是一系列特例+fallback 实现的

class map(Iterator[_S]):
    @overload
    def __new__(cls, func: Callable[[_T1], _S], iter1: Iterable[_T1], /) -> Self: ...
    @overload
    def __new__(cls, func: Callable[[_T1, _T2], _S], iter1: Iterable[_T1], iter2: Iterable[_T2], /) -> Self: ...
    @overload
    def __new__(
        cls, func: Callable[[_T1, _T2, _T3], _S], iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], /
    ) -> Self: ...
    @overload
    def __new__(
        cls,
        func: Callable[[_T1, _T2, _T3, _T4], _S],
        iter1: Iterable[_T1],
        iter2: Iterable[_T2],
        iter3: Iterable[_T3],
        iter4: Iterable[_T4],
        /,
    ) -> Self: ...
    @overload
    def __new__(
        cls,
        func: Callable[[_T1, _T2, _T3, _T4, _T5], _S],
        iter1: Iterable[_T1],
        iter2: Iterable[_T2],
        iter3: Iterable[_T3],
        iter4: Iterable[_T4],
        iter5: Iterable[_T5],
        /,
    ) -> Self: ...
    @overload
    def __new__(
        cls,
        func: Callable[..., _S],
        iter1: Iterable[Any],
        iter2: Iterable[Any],
        iter3: Iterable[Any],
        iter4: Iterable[Any],
        iter5: Iterable[Any],
        iter6: Iterable[Any],
        /,
        *iterables: Iterable[Any],
    ) -> Self: ...
    def __iter__(self) -> Self: ...
    def __next__(self) -> _S: ...

python/typing#1383 中描述的 Map 貌似可以实现我所需要的这种表达,但是目前连 PEP 都没呢……

Related links

PCard-66972

Copy link

paddle-bot bot commented Jul 21, 2024

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@SigureMo SigureMo requested a review from zrr1999 July 21, 2024 19:45
@SigureMo SigureMo changed the title [Typing] Add type annotations for python/paddle/reader/decorator.py [Typing][B-93] Add type annotations for python/paddle/reader/decorator.py Jul 21, 2024
@zrr1999 zrr1999 merged commit 0ba68a4 into PaddlePaddle:develop Jul 22, 2024
31 checks passed
@zrr1999 zrr1999 deleted the typing/b-93 branch July 22, 2024 03:56
lixcli pushed a commit to lixcli/Paddle that referenced this pull request Jul 22, 2024
…or.py` (PaddlePaddle#66305)

* [Typing] Add type annotations for `python/paddle/reader/decorator.py`

* missing pep563
inaomIIsfarell pushed a commit to inaomIIsfarell/Paddle that referenced this pull request Jul 31, 2024
…or.py` (PaddlePaddle#66305)

* [Typing] Add type annotations for `python/paddle/reader/decorator.py`

* missing pep563
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants