test_retype.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:retype 作者: ambv 项目源码 文件源码
def test_alias_many(self) -> None:
        pyi_txt = """
        from typing import TypeVar

        _T = TypeVar('_T', bound=str)
        _EitherStr = Union[str, bytes]
        _MaybeStrings = List[Optional[_EitherStr]]
        SOME_GLOBAL: int

        def fun(error: _T) -> _T: ...
        def fun2(errors: _MaybeStrings) -> None: ...
        """
        src_txt = """
        "Docstring"

        from __future__ import print_function

        import sys

        SOME_GLOBAL: int = 0

        def fun(error):
            return error

        @decorator
        def fun2(errors) -> None:
            for error in errors:
                if not error:
                    continue
                print(error, file=sys.stderr)
        """
        expected_txt = """
        "Docstring"

        from __future__ import print_function

        import sys

        from typing import TypeVar
        SOME_GLOBAL: int = 0
        _T = TypeVar('_T', bound=str)

        def fun(error: _T) -> _T:
            return error

        _EitherStr = Union[str, bytes]
        _MaybeStrings = List[Optional[_EitherStr]]
        @decorator
        def fun2(errors: _MaybeStrings) -> None:
            for error in errors:
                if not error:
                    continue
                print(error, file=sys.stderr)
        """
        self.assertReapply(pyi_txt, src_txt, expected_txt)
        self.assertReapplyVisible(pyi_txt, src_txt, expected_txt)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号