本文整理汇总了Python中six.create_bound_method方法的典型用法代码示例。如果您正苦于以下问题:Python six.create_bound_method方法的具体用法?Python six.create_bound_method怎么用?Python six.create_bound_method使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类six
的用法示例。
在下文中一共展示了six.create_bound_method方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getLogger
# 需要导入模块: import six [as 别名]
# 或者: from six import create_bound_method [as 别名]
def getLogger(name):
"""Create logger with custom exception() method
"""
def exception(self, msg, *args, **kwargs):
extra = kwargs.setdefault('extra', {})
extra['exc_fullstack'] = self.isEnabledFor(logging.DEBUG)
kwargs['exc_info'] = True
self.log(logging.ERROR, msg, *args, **kwargs)
logger = logging.getLogger(name)
logger.exception = six.create_bound_method(exception, logger)
return logger
示例2: test_create_bound_method
# 需要导入模块: import six [as 别名]
# 或者: from six import create_bound_method [as 别名]
def test_create_bound_method():
class X(object):
pass
def f(self):
return self
x = X()
b = six.create_bound_method(f, x)
assert isinstance(b, types.MethodType)
assert b() is x
示例3: to_graph
# 需要导入模块: import six [as 别名]
# 或者: from six import create_bound_method [as 别名]
def to_graph(func, recursive=True):
new_func = tf.autograph.to_graph(
func,
recursive=recursive,
experimental_optional_features=tf.autograph.experimental.Feature.ALL)
# TODO(b/127686409): Remove this.
if inspect.ismethod(func):
return six.create_bound_method(new_func, func.__self__)
return new_func
示例4: __getattr__
# 需要导入模块: import six [as 别名]
# 或者: from six import create_bound_method [as 别名]
def __getattr__(self, name):
if name in (_[0] for _ in getmembers(UserEditable, predicate=isroutine)) and \
self.is_content_editable:
self._content_editable = True
setattr(self, name, six.create_bound_method(
six.get_unbound_function(getattr(UserEditable, name)), self))
return getattr(self, name)
else:
raise AttributeError("Element '{}' has no attribute "
"'{}'".format(self.__class__.__name__.capitalize(), name))
示例5: _give_columns_django_field_attributes
# 需要导入模块: import six [as 别名]
# 或者: from six import create_bound_method [as 别名]
def _give_columns_django_field_attributes(self):
"""
Add Django Field attributes to each cqlengine.Column instance.
So that the Django Options class may interact with it as if it were
a Django Field.
"""
methods_to_add = (
django_field_methods.value_from_object,
django_field_methods.value_to_string,
django_field_methods.get_attname,
django_field_methods.get_cache_name,
django_field_methods.pre_save,
django_field_methods.get_prep_value,
django_field_methods.get_choices,
django_field_methods.get_choices_default,
django_field_methods.save_form_data,
django_field_methods.formfield,
django_field_methods.get_db_prep_value,
django_field_methods.get_db_prep_save,
django_field_methods.db_type_suffix,
django_field_methods.select_format,
django_field_methods.get_internal_type,
django_field_methods.get_attname_column,
django_field_methods.check,
django_field_methods._check_field_name,
django_field_methods._check_db_index,
django_field_methods.deconstruct,
django_field_methods.run_validators,
django_field_methods.clean,
django_field_methods.get_db_converters,
django_field_methods.get_prep_lookup,
django_field_methods.get_db_prep_lookup,
django_field_methods.get_filter_kwargs_for_object,
django_field_methods.set_attributes_from_name,
django_field_methods.db_parameters,
django_field_methods.get_pk_value_on_save,
django_field_methods.get_col,
)
for name, cql_column in six.iteritems(self._defined_columns):
self._set_column_django_attributes(cql_column=cql_column, name=name)
for method in methods_to_add:
try:
method_name = method.func_name
except AttributeError:
# python 3
method_name = method.__name__
new_method = six.create_bound_method(method, cql_column)
setattr(cql_column, method_name, new_method)
示例6: create_multi_node_evaluator
# 需要导入模块: import six [as 别名]
# 或者: from six import create_bound_method [as 别名]
def create_multi_node_evaluator(actual_evaluator, communicator):
"""Create a multi node evaluator from a normal evaluator.
Actually this method patches the evaluator to work in multi node
environment. This method adds several hidden attributes starting
with `_mn_` prefix.
Args:
actual_evaluator: evaluator to be patched
(e.g., ``chainer.training.extensions.Evaluator``)
communicator: ChainerMN communicator
Returns:
The multi-node patched ``actual_evaluator``.
.. note:: After patched, original evaluator does not work
correctly in non-MPI environment.
"""
actual_evaluator._mn_original_evaluate = actual_evaluator.evaluate
actual_evaluator._mn_communicator = communicator
def new_evaluate(self):
local_mean_dict = self._mn_original_evaluate()
# ChainerX support:
# We need convert chainerx ndarray to Native array because
# (1) allreduce_obj is used to compute global mean values, since
# a simple allreduce operation cannot be applied in evaluation.
# (2) allreduce_obj calls mpi4py.allreduce, which pickles the object
# (3) chainerx.ndarray preserves CUDA device internally when pickled
# (4) An error will occur when an ndarray is unpickled in another
# process
array0 = list(local_mean_dict.values())[0]
xp = backend.get_array_module(array0)
if xp == chx and array0.device.backend.name == 'cuda':
# Results of evaluation is fairly small, so
# the ndarray is transferred to CPU and allreduce()-ed.
# NOTE: Matrices for evaluation are transferred to the host memory
# and sent via MPI instead of NCCL. Although evaluation matrices
# are small in most cases, this is a potential performance issue.
local_mean_dict = {
name: chx.to_numpy(value)
for name, value in local_mean_dict.items()
}
global_mean_dict = {
name:
self._mn_communicator.allreduce_obj(
value) / self._mn_communicator.size
for name, value in sorted(local_mean_dict.items())
}
return global_mean_dict
actual_evaluator.evaluate = six.create_bound_method(
new_evaluate, actual_evaluator)
return actual_evaluator