本文整理汇总了Python中builtins.callable方法的典型用法代码示例。如果您正苦于以下问题:Python builtins.callable方法的具体用法?Python builtins.callable怎么用?Python builtins.callable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类builtins
的用法示例。
在下文中一共展示了builtins.callable方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pow
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import callable [as 别名]
def pow(x, y, z=_SENTINEL):
"""
pow(x, y[, z]) -> number
With two arguments, equivalent to x**y. With three arguments,
equivalent to (x**y) % z, but may be more efficient (e.g. for ints).
"""
# Handle newints
if isinstance(x, newint):
x = long(x)
if isinstance(y, newint):
y = long(y)
if isinstance(z, newint):
z = long(z)
try:
if z == _SENTINEL:
return _builtin_pow(x, y)
else:
return _builtin_pow(x, y, z)
except ValueError:
if z == _SENTINEL:
return _builtin_pow(x+0j, y)
else:
return _builtin_pow(x+0j, y, z)
# ``future`` doesn't support Py3.0/3.1. If we ever did, we'd add this:
# callable = __builtin__.callable
示例2: callable
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import callable [as 别名]
def callable(obj):
if hasattr(obj, '__call__'): return True
if isinstance(obj, (ClassType, type)): return True
return False
示例3: pow
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import callable [as 别名]
def pow(x, y, z=_SENTINEL):
"""
pow(x, y[, z]) -> number
With two arguments, equivalent to x**y. With three arguments,
equivalent to (x**y) % z, but may be more efficient (e.g. for ints).
"""
# Handle newints
if isinstance(x, newint):
x = long(x)
if isinstance(y, newint):
y = long(y)
if isinstance(z, newint):
z = long(z)
try:
if z == _SENTINEL:
return _builtin_pow(x, y)
else:
return _builtin_pow(x, y, z)
except ValueError:
if z == _SENTINEL:
return _builtin_pow(x+0j, y)
else:
return _builtin_pow(x+0j, y, z)
# ``future`` doesn't support Py3.0/3.1. If we ever did, we'd add this:
# callable = __builtin__.callable
示例4: callable
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import callable [as 别名]
def callable(obj):
return isinstance(obj, Callable)
示例5: __getattr__
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import callable [as 别名]
def __getattr__(self, attr):
proxy = self.__proxy
if proxy and hasattr(proxy, attr):
return getattr(proxy, attr)
attrmap = self.__attrmap
if attr in attrmap:
source = attrmap[attr]
if callable(source):
value = source()
else:
value = _import_object(source)
setattr(self, attr, value)
self.__log.debug("loaded lazy attr %r: %r", attr, value)
return value
raise AttributeError("'module' object has no attribute '%s'" % (attr,))
示例6: evaluate_dependencies
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import callable [as 别名]
def evaluate_dependencies(self, context, callback=None):
"""
Evaluate the dependencies of this operation and discard the values.
Parameters
----------
context : dict
Normalised context in which to evaluate the operation.
callback : callable or None
Callback to be evaluated when an operation is evaluated.
"""
for operation in self.dependencies:
operation.evaluate(context, callback)
示例7: evaluate
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import callable [as 别名]
def evaluate(self, context, callback=None):
"""
Evaluate the operation given a context.
Parameters
----------
context : dict
Normalised context in which to evaluate the operation.
callback : callable or None
Callback to be evaluated when an operation is evaluated.
Returns
-------
value : object
Output of the operation given the context.
"""
# Evaluate all explicit dependencies first
self.evaluate_dependencies(context, callback)
if self in context:
return context[self]
# Evaluate the parents
partial = functools.partial(self.evaluate_operation, context=context, callback=callback)
args = [partial(arg) for arg in self.args]
kwargs = {key: partial(value) for key, value in self.kwargs.items()}
# Evaluate the operation
callback = callback or _noop_callback
with callback(self, context):
context[self] = value = self._evaluate(*args, **kwargs)
return value
示例8: call
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import callable [as 别名]
def call(func, *args, **kwargs):
"""
Call `func` with positional arguments `args` and keyword arguments `kwargs`.
Parameters
----------
func : callable
Function to call when the operation is executed.
args : list
Sequence of positional arguments passed to `func`.
kwargs : dict
Mapping of keyword arguments passed to `func`.
"""
return func(*args, **kwargs)
示例9: __init__
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import callable [as 别名]
def __init__(self, callable):
self._callable = callable
示例10: test_Callable_OK
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import callable [as 别名]
def test_Callable_OK(): # TODO: What's going wrong here?
assert callable(foo_Callable)
# Not even one of the following works:
foo_Callable(lambda: foo_Callable)
foo_Callable(lambda x: 2*x)
foo_Callable(builtins.callable)
foo_Callable(builtins.dict)
foo_Callable(builtins.len)
foo_Callable(foo_Callable)
############################################################################
# _Protocol
# is handled by TypeChecker without special code, so we do not test them all
示例11: apply
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import callable [as 别名]
def apply(self, fetches, context=None, *, callback=None, **kwargs):
"""
Evaluate one or more operations given a context.
.. note::
This function modifies the context in place. Use :code:`context=context.copy()` to avoid
the context being modified.
Parameters
----------
fetches : list[str or Operation] or str or Operation
One or more `Operation` instances or names to evaluate.
context : dict or None
Context in which to evaluate the operations.
callback : callable or None
Callback to be evaluated when an operation is evaluated.
kwargs : dict
Additional context information keyed by variable name.
Returns
-------
values : tuple[object]
Output of the operations given the context.
Raises
------
ValueError
If `fetches` is not an `Operation` instance, operation name, or a sequence thereof.
ValueError
If `context` is not a mapping.
"""
if isinstance(fetches, (str, Operation)):
fetches = [fetches]
single = True
elif isinstance(fetches, collections.Sequence):
single = False
else:
raise ValueError("`fetches` must be an `Operation` instance, operation name, or a "
"sequence thereof.")
fetches = [self.normalize_operation(operation) for operation in fetches]
context = self.normalize_context(context, **kwargs)
values = [fetch.evaluate_operation(fetch, context, callback=callback) for fetch in fetches]
return values[0] if single else tuple(values)