當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。