本文整理匯總了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, {})
示例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, {})
示例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})
示例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})
示例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
示例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