本文整理匯總了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)