Python six.create_bound_method() Examples
The following are 9
code examples of six.create_bound_method().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
six
, or try the search function
.
Example #1
Source File: log.py From custodia with GNU General Public License v3.0 | 5 votes |
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
Example #2
Source File: test_six.py From six with MIT License | 5 votes |
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
Example #3
Source File: reference_test_base.py From autograph with Apache License 2.0 | 5 votes |
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
Example #4
Source File: test_six.py From c4ddev with MIT License | 5 votes |
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
Example #5
Source File: test_six.py From data with GNU General Public License v3.0 | 5 votes |
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
Example #6
Source File: test_six.py From data with GNU General Public License v3.0 | 5 votes |
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
Example #7
Source File: element.py From nerodia with MIT License | 5 votes |
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))
Example #8
Source File: __init__.py From django-cassandra-engine with BSD 2-Clause "Simplified" License | 4 votes |
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)
Example #9
Source File: multi_node_evaluator.py From chainer with MIT License | 4 votes |
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