当前位置: 首页>>代码示例>>Python>>正文


Python typing.overload方法代码示例

本文整理汇总了Python中typing.overload方法的典型用法代码示例。如果您正苦于以下问题:Python typing.overload方法的具体用法?Python typing.overload怎么用?Python typing.overload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在typing的用法示例。


在下文中一共展示了typing.overload方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_typingOverloadAsync

# 需要导入模块: import typing [as 别名]
# 或者: from typing import overload [as 别名]
def test_typingOverloadAsync(self):
        """Allow intentional redefinitions via @typing.overload (async)"""
        self.flakes("""
        from typing import overload

        @overload
        async def f(s):  # type: (None) -> None
            pass

        @overload
        async def f(s):  # type: (int) -> int
            pass

        async def f(s):
            return s
        """) 
开发者ID:PyCQA,项目名称:pyflakes,代码行数:18,代码来源:test_type_annotations.py

示例2: check_tuple

# 需要导入模块: import typing [as 别名]
# 或者: from typing import overload [as 别名]
def check_tuple(sub_validators: List[Validator[ResultT]]) -> Validator[Tuple[Any, ...]]:
    def f(var_name: str, val: object) -> Tuple[Any, ...]:
        if not isinstance(val, tuple):
            raise ValidationError(_('{var_name} is not a tuple').format(var_name=var_name))

        desired_len = len(sub_validators)
        if desired_len != len(val):
            raise ValidationError(_('{var_name} should have exactly {desired_len} items').format(
                var_name=var_name, desired_len=desired_len,
            ))

        for i, sub_validator in enumerate(sub_validators):
            vname = f'{var_name}[{i}]'
            sub_validator(vname, val[i])

        return val
    return f

# https://zulip.readthedocs.io/en/latest/testing/mypy.html#using-overload-to-accurately-describe-variations 
开发者ID:zulip,项目名称:zulip,代码行数:21,代码来源:validator.py

示例3: test_overload_with_multiple_decorators

# 需要导入模块: import typing [as 别名]
# 或者: from typing import overload [as 别名]
def test_overload_with_multiple_decorators(self):
        self.flakes("""
            from typing import overload
            dec = lambda f: f

            @dec
            @overload
            def f(x):  # type: (int) -> int
                pass

            @dec
            @overload
            def f(x):  # type: (str) -> str
                pass

            @dec
            def f(x): return x
       """) 
开发者ID:PyCQA,项目名称:pyflakes,代码行数:20,代码来源:test_type_annotations.py

示例4: test_all

# 需要导入模块: import typing [as 别名]
# 或者: from typing import overload [as 别名]
def test_all(self):
        from typing import __all__ as a
        # Just spot-check the first and last of every category.
        self.assertIn('AbstractSet', a)
        self.assertIn('ValuesView', a)
        self.assertIn('cast', a)
        self.assertIn('overload', a)
        if hasattr(contextlib, 'AbstractContextManager'):
            self.assertIn('ContextManager', a)
        # Check that io and re are not exported.
        self.assertNotIn('io', a)
        self.assertNotIn('re', a)
        # Spot-check that stdlib modules aren't exported.
        self.assertNotIn('os', a)
        self.assertNotIn('sys', a)
        # Check that Text is defined.
        self.assertIn('Text', a)
        # Check previously missing classes.
        self.assertIn('SupportsBytes', a)
        self.assertIn('SupportsComplex', a) 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:22,代码来源:test_typing.py

示例5: __iter__

# 需要导入模块: import typing [as 别名]
# 或者: from typing import overload [as 别名]
def __iter__(self) -> typing.Iterator[KeyInfo]:
        """Iterate over KeyInfo objects."""
        for key_and_modifiers in self._iter_keys():
            key = Qt.Key(int(key_and_modifiers) & ~Qt.KeyboardModifierMask)
            modifiers = Qt.KeyboardModifiers(  # type: ignore[call-overload]
                int(key_and_modifiers) & Qt.KeyboardModifierMask)
            yield KeyInfo(key=key, modifiers=modifiers) 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:9,代码来源:keyutils.py

示例6: overload

# 需要导入模块: import typing [as 别名]
# 或者: from typing import overload [as 别名]
def overload(x):
        # type: (F) -> F
        return x 
开发者ID:getsentry,项目名称:sentry-python,代码行数:5,代码来源:serverless.py

示例7: overload

# 需要导入模块: import typing [as 别名]
# 或者: from typing import overload [as 别名]
def overload(x):
        # type: (T) -> T
        return x 
开发者ID:getsentry,项目名称:sentry-python,代码行数:5,代码来源:hub.py

示例8: __getitem__

# 需要导入模块: import typing [as 别名]
# 或者: from typing import overload [as 别名]
def __getitem__(self, index: int) -> Tensor:
        if not self.atomic:
            return self.tensors[index]

        if index != 0:
            raise IndexError('atomic batch allows index 0 only')

        return self.tensor

    # NOTE(sublee): pyflakes can't detect "overload" instead of "typing.overload". 
开发者ID:kakaobrain,项目名称:torchgpipe,代码行数:12,代码来源:microbatch.py

示例9: overload

# 需要导入模块: import typing [as 别名]
# 或者: from typing import overload [as 别名]
def overload(f):  # noqa: F811
        return f 
开发者ID:pytest-dev,项目名称:pytest,代码行数:4,代码来源:compat.py

示例10: test_overload_fails

# 需要导入模块: import typing [as 别名]
# 或者: from typing import overload [as 别名]
def test_overload_fails(self):
        from typing import overload

        with self.assertRaises(RuntimeError):
            @overload
            def blah():
                pass 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:9,代码来源:test_typing.py

示例11: test_all

# 需要导入模块: import typing [as 别名]
# 或者: from typing import overload [as 别名]
def test_all(self):
        from typing import __all__ as a
        # Just spot-check the first and last of every category.
        assert 'AbstractSet' in a
        assert 'ValuesView' in a
        assert 'cast' in a
        assert 'overload' in a
        assert 'io' in a
        assert 're' in a
        # Spot-check that stdlib modules aren't exported.
        assert 'os' not in a
        assert 'sys' not in a 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:14,代码来源:test_typing.py

示例12: test_typingOverload

# 需要导入模块: import typing [as 别名]
# 或者: from typing import overload [as 别名]
def test_typingOverload(self):
        """Allow intentional redefinitions via @typing.overload"""
        self.flakes("""
        import typing
        from typing import overload

        @overload
        def f(s):  # type: (None) -> None
            pass

        @overload
        def f(s):  # type: (int) -> int
            pass

        def f(s):
            return s

        @typing.overload
        def g(s):  # type: (None) -> None
            pass

        @typing.overload
        def g(s):  # type: (int) -> int
            pass

        def g(s):
            return s
        """) 
开发者ID:PyCQA,项目名称:pyflakes,代码行数:30,代码来源:test_type_annotations.py

示例13: test_typingExtensionsOverload

# 需要导入模块: import typing [as 别名]
# 或者: from typing import overload [as 别名]
def test_typingExtensionsOverload(self):
        """Allow intentional redefinitions via @typing_extensions.overload"""
        self.flakes("""
        import typing_extensions
        from typing_extensions import overload

        @overload
        def f(s):  # type: (None) -> None
            pass

        @overload
        def f(s):  # type: (int) -> int
            pass

        def f(s):
            return s

        @typing_extensions.overload
        def g(s):  # type: (None) -> None
            pass

        @typing_extensions.overload
        def g(s):  # type: (int) -> int
            pass

        def g(s):
            return s
        """) 
开发者ID:PyCQA,项目名称:pyflakes,代码行数:30,代码来源:test_type_annotations.py

示例14: test_overload_in_class

# 需要导入模块: import typing [as 别名]
# 或者: from typing import overload [as 别名]
def test_overload_in_class(self):
        self.flakes("""
        from typing import overload

        class C:
            @overload
            def f(self, x):  # type: (int) -> int
                pass

            @overload
            def f(self, x):  # type: (str) -> str
                pass

            def f(self, x): return x
        """) 
开发者ID:PyCQA,项目名称:pyflakes,代码行数:17,代码来源:test_type_annotations.py

示例15: test_overload_fails

# 需要导入模块: import typing [as 别名]
# 或者: from typing import overload [as 别名]
def test_overload_fails(self):
        from typing import overload

        with self.assertRaises(RuntimeError):

            @overload
            def blah():
                pass

            blah() 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:12,代码来源:test_typing.py


注:本文中的typing.overload方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。