本文整理汇总了Python中collections.abc.Callable方法的典型用法代码示例。如果您正苦于以下问题:Python abc.Callable方法的具体用法?Python abc.Callable怎么用?Python abc.Callable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块collections.abc的用法示例。
在下文中一共展示了abc.Callable方法的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: assert_increases
点赞 6
# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Callable [as 别名]
def assert_increases(self, delta: int, func: Callable, name=""):
""" shortcuts to verify func change is equal to delta """
test_case = self
class Detector:
def __init__(self):
self.previous = None
def __enter__(self):
self.previous = func()
def __exit__(self, exc_type, exc_val, exc_tb):
if not exc_val:
test_case.assertEqual(
self.previous + delta, func(), "{} should change {}".format(name, delta).strip()
)
return Detector()
开发者ID:zaihui,项目名称:hutils,代码行数:20,
示例2: __get_default
点赞 6
# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Callable [as 别名]
def __get_default(self, item):
default_value = self._box_config['default_box_attr']
if default_value in (self.__class__, dict):
value = self.__class__(**self.__box_config())
elif isinstance(default_value, dict):
value = self.__class__(**self.__box_config(), **default_value)
elif isinstance(default_value, list):
value = box.BoxList(**self.__box_config())
elif isinstance(default_value, Callable):
value = default_value()
elif hasattr(default_value, 'copy'):
value = default_value.copy()
else:
value = default_value
self.__convert_and_store(item, value)
return value
开发者ID:cdgriffith,项目名称:Box,代码行数:18,
示例3: test_Callable
点赞 6
# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Callable [as 别名]
def test_Callable(self):
non_samples = [None, 42, 3.14, 1j,
"", b"", (), [], {}, set(),
(lambda: (yield))(),
(x for x in []),
]
for x in non_samples:
self.assertNotIsInstance(x, Callable)
self.assertFalse(issubclass(type(x), Callable), repr(type(x)))
samples = [lambda: None,
type, int, object,
len,
list.append, [].append,
]
for x in samples:
self.assertIsInstance(x, Callable)
self.assertTrue(issubclass(type(x), Callable), repr(type(x)))
self.validate_abstract_methods(Callable, '__call__')
self.validate_isinstance(Callable, '__call__')
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,
示例4: __new__
点赞 6
# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Callable [as 别名]
def __new__(cls, name, bases, namespace, _root=False,
args=None, result=None):
if args is None and result is None:
pass # Must be 'class Callable'.
else:
if args is not Ellipsis:
if not isinstance(args, list):
raise TypeError("Callable[args, result]: "
"args must be a list."
" Got %.100r." % (args,))
msg = "Callable[[arg, ...], result]: each arg must be a type."
args = tuple(_type_check(arg, msg) for arg in args)
msg = "Callable[args, result]: result must be a type."
result = _type_check(result, msg)
self = super().__new__(cls, name, bases, namespace, _root=_root)
self.__args__ = args
self.__result__ = result
return self
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:20,
示例5: _get_check
点赞 6
# 需要导入模块: from collections i