當前位置: 首頁>>代碼示例>>Python>>正文


Python six.create_bound_method方法代碼示例

本文整理匯總了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 
開發者ID:latchset,項目名稱:custodia,代碼行數:14,代碼來源:log.py

示例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 
開發者ID:benjaminp,項目名稱:six,代碼行數:11,代碼來源:test_six.py

示例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 
開發者ID:tensorflow,項目名稱:autograph,代碼行數:11,代碼來源:reference_test_base.py

示例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)) 
開發者ID:watir,項目名稱:nerodia,代碼行數:12,代碼來源:element.py

示例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) 
開發者ID:r4fek,項目名稱:django-cassandra-engine,代碼行數:52,代碼來源:__init__.py

示例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 
開發者ID:chainer,項目名稱:chainer,代碼行數:60,代碼來源:multi_node_evaluator.py


注:本文中的six.create_bound_method方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。