當前位置: 首頁>>代碼示例>>Python>>正文


Python typing.no_type_check方法代碼示例

本文整理匯總了Python中typing.no_type_check方法的典型用法代碼示例。如果您正苦於以下問題:Python typing.no_type_check方法的具體用法?Python typing.no_type_check怎麽用?Python typing.no_type_check使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在typing的用法示例。


在下文中一共展示了typing.no_type_check方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_no_type_check

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import no_type_check [as 別名]
def test_no_type_check(self):

        @no_type_check
        def foo(a: 'whatevers') -> {}:
            pass

        th = get_type_hints(foo)
        self.assertEqual(th, {}) 
開發者ID:ShikyoKira,項目名稱:Project-New-Reign---Nemesis-Main,代碼行數:10,代碼來源:test_typing.py

示例2: test_no_type_check_class

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import no_type_check [as 別名]
def test_no_type_check_class(self):

        @no_type_check
        class C:
            def foo(a: 'whatevers') -> {}:
                pass

        cth = get_type_hints(C.foo)
        self.assertEqual(cth, {})
        ith = get_type_hints(C().foo)
        self.assertEqual(ith, {}) 
開發者ID:ShikyoKira,項目名稱:Project-New-Reign---Nemesis-Main,代碼行數:13,代碼來源:test_typing.py

示例3: test_no_type_check_no_bases

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import no_type_check [as 別名]
def test_no_type_check_no_bases(self):
        class C:
            def meth(self, x: int): ...
        @no_type_check
        class D(C):
            c = C
        # verify that @no_type_check never affects bases
        self.assertEqual(get_type_hints(C.meth), {'x': int}) 
開發者ID:ShikyoKira,項目名稱:Project-New-Reign---Nemesis-Main,代碼行數:10,代碼來源:test_typing.py

示例4: test_respect_no_type_check

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import no_type_check [as 別名]
def test_respect_no_type_check(self):
        @no_type_check
        class NoTpCheck:
            class Inn:
                def __init__(self, x: 'not a type'): ...
        self.assertTrue(NoTpCheck.__no_type_check__)
        self.assertTrue(NoTpCheck.Inn.__init__.__no_type_check__)
        self.assertEqual(gth(ann_module2.NTC.meth), {})
        class ABase(Generic[T]):
            def meth(x: int): ...
        @no_type_check
        class Der(ABase): ...
        self.assertEqual(gth(ABase.meth), {'x': int}) 
開發者ID:ShikyoKira,項目名稱:Project-New-Reign---Nemesis-Main,代碼行數:15,代碼來源:test_typing.py

示例5: no_type_check

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import no_type_check [as 別名]
def no_type_check(memb):
    """Works like typing.no_type_check, but also supports cases where
    typing.no_type_check fails due to AttributeError. This can happen,
    because typing.no_type_check wants to access __no_type_check__, which
    might fail if e.g. a class is using slots or an object doesn't support
    custom attributes.
    """
    try:
        return typing.no_type_check(memb)
    except(AttributeError):
        _not_type_checked.add(memb)
        return memb 
開發者ID:Stewori,項目名稱:pytypes,代碼行數:14,代碼來源:typechecker.py

示例6: is_no_type_check

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import no_type_check [as 別名]
def is_no_type_check(memb):
    """Checks if an object was annotated with @no_type_check
    (from typing or pytypes.typechecker).
    """
    try:
        return hasattr(memb, '__no_type_check__') and memb.__no_type_check__ or \
                memb in _not_type_checked
    except TypeError:
        return False 
開發者ID:Stewori,項目名稱:pytypes,代碼行數:11,代碼來源:typechecker.py


注:本文中的typing.no_type_check方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。