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


Python types.BuiltinFunctionType方法代碼示例

本文整理匯總了Python中types.BuiltinFunctionType方法的典型用法代碼示例。如果您正苦於以下問題:Python types.BuiltinFunctionType方法的具體用法?Python types.BuiltinFunctionType怎麽用?Python types.BuiltinFunctionType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在types的用法示例。


在下文中一共展示了types.BuiltinFunctionType方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: import_object

# 需要導入模塊: import types [as 別名]
# 或者: from types import BuiltinFunctionType [as 別名]
def import_object(self):
        ret = ClassLevelDocumenter.import_object(self)
        if isinstance(self.object, classmethod) or \
               (isinstance(self.object, MethodType) and
                self.object.im_self is not None):
            self.directivetype = 'classmethod'
            # document class and static members before ordinary ones
            self.member_order = self.member_order - 1
        elif isinstance(self.object, FunctionType) or \
             (isinstance(self.object, BuiltinFunctionType) and
              self.object.__self__ is not None):
            self.directivetype = 'staticmethod'
            # document class and static members before ordinary ones
            self.member_order = self.member_order - 1
        else:
            self.directivetype = 'method'
        return ret 
開發者ID:cihologramas,項目名稱:pyoptools,代碼行數:19,代碼來源:sage_autodoc.py

示例2: get_module_functions

# 需要導入模塊: import types [as 別名]
# 或者: from types import BuiltinFunctionType [as 別名]
def get_module_functions(modules):
  """Finds functions that do not have implemented derivatives.

  Args:
    modules: A list of Python modules. Functions contained in these modules
        will be checked for membership in 'implemented', and if not found,
        will be added to an 'unimplemented' set
    implemented: A Python object containing implemented derivatives. A function
        should be checkable for membership using the `fn in implemented` syntax.

  Returns:
    module_fns: A set of functions, builtins or ufuncs in `modules`.
  """
  module_fns = set()
  for module in modules:
    for key in dir(module):
      attr = getattr(module, key)
      if isinstance(
          attr, (types.BuiltinFunctionType, types.FunctionType, numpy.ufunc)):
        module_fns.add(attr)
  return module_fns 
開發者ID:google,項目名稱:tangent,代碼行數:23,代碼來源:grads.py

示例3: short_repr

# 需要導入模塊: import types [as 別名]
# 或者: from types import BuiltinFunctionType [as 別名]
def short_repr(obj):
    if isinstance(obj, (type, types.ModuleType, types.BuiltinMethodType,
                        types.BuiltinFunctionType)):
        return obj.__name__
    if isinstance(obj, types.MethodType):
        try:
            if obj.__self__ is not None:
                return obj.__func__.__name__ + ' (bound)'
            else:
                return obj.__func__.__name__
        except AttributeError:
            # Python < 2.6 compatibility
            if obj.im_self is not None:
                return obj.im_func.__name__ + ' (bound)'
            else:
                return obj.im_func.__name__

    if isinstance(obj, types.FrameType):
        return '%s:%s' % (obj.f_code.co_filename, obj.f_lineno)
    if isinstance(obj, (tuple, list, dict, set)):
        return '%d items' % len(obj)
    return repr(obj)[:40] 
開發者ID:Exa-Networks,項目名稱:exaddos,代碼行數:24,代碼來源:objgraph.py

示例4: typeof

# 需要導入模塊: import types [as 別名]
# 或者: from types import BuiltinFunctionType [as 別名]
def typeof(self, cdecl):
        """Parse the C type given as a string and return the
        corresponding <ctype> object.
        It can also be used on 'cdata' instance to get its C type.
        """
        if isinstance(cdecl, basestring):
            return self._typeof(cdecl)
        if isinstance(cdecl, self.CData):
            return self._backend.typeof(cdecl)
        if isinstance(cdecl, types.BuiltinFunctionType):
            res = _builtin_function_type(cdecl)
            if res is not None:
                return res
        if (isinstance(cdecl, types.FunctionType)
                and hasattr(cdecl, '_cffi_base_type')):
            with self._lock:
                return self._get_cached_btype(cdecl._cffi_base_type)
        raise TypeError(type(cdecl)) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:20,代碼來源:api.py

示例5: smart_decorator

# 需要導入模塊: import types [as 別名]
# 或者: from types import BuiltinFunctionType [as 別名]
def smart_decorator(f, create_decorator):
    if isinstance(f, types.FunctionType):
        return wraps(f)(create_decorator(f, True))

    elif isinstance(f, (classtype, type, types.BuiltinFunctionType)):
        return wraps(f)(create_decorator(f, False))

    elif isinstance(f, types.MethodType):
        return wraps(f)(create_decorator(f.__func__, True))

    elif isinstance(f, partial):
        # wraps does not work for partials in 2.7: https://bugs.python.org/issue3445
        return wraps(f.func)(create_decorator(lambda *args, **kw: f(*args[1:], **kw), True))

    else:
        return create_decorator(f.__func__.__call__, True) 
開發者ID:lark-parser,項目名稱:lark,代碼行數:18,代碼來源:json_parser.py

示例6: order_attributes

# 需要導入模塊: import types [as 別名]
# 或者: from types import BuiltinFunctionType [as 別名]
def order_attributes(attrs):
    constants = {}
    functions = {}
    classes = {}
    
    for key, value in attrs.items():
        if isinstance(value, type(int.real)) or key in ("__abstractmethods__", "__base__", "__bases__", "__class__", "__dict__", "__dictoffset__", "__file__", "__flags__", "__itemsize__", "__module__", "__name__", "__package__", "__subclasses__", "__weakrefoffset__"):
            pass
        elif isinstance(value, (type, types.ClassType)):
            classes[key] = value
        elif isinstance(value, (types.FunctionType, types.BuiltinFunctionType, type(list.append), type(object.__init__), classmethod, staticmethod)):
            if not (key.startswith("__") and key.endswith("__")):
                functions[key] = value
        else:
            constants[key] = value
    
    constants = sorted_mapping(constants)
    functions = sorted_mapping(functions)
    classes = sorted_mapping(classes)
    classes_reverse = collections.OrderedDict((v, k) for k, v in classes.items())
    
    classes_ordered = collections.OrderedDict((classes_reverse[cls], cls) for cls in order_classes(classes.values()))
    
    return collections.OrderedDict(constants.items() + functions.items() + classes_ordered.items()) 
開發者ID:dgelessus,項目名稱:pythonista-scripts,代碼行數:26,代碼來源:moduledump.py

示例7: stringify_attributes

# 需要導入模塊: import types [as 別名]
# 或者: from types import BuiltinFunctionType [as 別名]
def stringify_attributes(attrs):
    lines = []
    
    for k, v in attrs.items():
        if isinstance(v, (type, types.ClassType)):
            lines.append(stringify_class(k, v))
        elif isinstance(v, (types.MethodType, type(list.append), type(object.__init__))):
            lines.append(stringify_method(k, v))
        elif isinstance(v, classmethod):
            lines.append(stringify_classmethod(k, v))
        elif isinstance(v, (types.FunctionType, types.BuiltinFunctionType, staticmethod)):
            lines.append(stringify_function(k, v))
        else:
            lines.append(stringify_constant(k, v))
    
    return u"\n".join(lines) 
開發者ID:dgelessus,項目名稱:pythonista-scripts,代碼行數:18,代碼來源:moduledump.py

示例8: _decode_function

# 需要導入模塊: import types [as 別名]
# 或者: from types import BuiltinFunctionType [as 別名]
def _decode_function(self, obj: dict) -> typing.Union[
            types.FunctionType, types.BuiltinFunctionType]:
        """
        Decode function

        Parameters
        ----------
        obj : dict
            dict to be decoded

        Returns
        -------
        typing.Union[types.FunctionType, types.BuiltinFunctionType]
            decoded function
        """
        # decode items in dict representation
        function_repr = self.decode(obj)
        return getattr(importlib.import_module(function_repr["module"]),
                       function_repr["name"]) 
開發者ID:delira-dev,項目名稱:delira,代碼行數:21,代碼來源:codecs.py

示例9: __enter__

# 需要導入模塊: import types [as 別名]
# 或者: from types import BuiltinFunctionType [as 別名]
def __enter__(self):
        next_envs = [env.copy() for env in self.envs]
        for env, next_env in zip(self.envs, next_envs):
            for (k, v) in env.items():
                if isinstance(v, (types.FunctionType, types.BuiltinFunctionType)):
                    if is_singledispatcher(v):
                        wrapper = self._transform_singledispatch(
                            v, self._wrap_fn)
                    else:
                        wrapper = self._wrap_fn(v)
                        if wrapper is v:
                            continue
                    next_env[k] = wrapper
                elif isinstance(v, type):
                    conditions = get_class_conditions(v)
                    if conditions.has_any():
                        self._wrap_class(v, conditions)
        for env, next_env in zip(self.envs, next_envs):
            env.update(next_env)
        return self 
開發者ID:pschanely,項目名稱:CrossHair,代碼行數:22,代碼來源:enforce.py

示例10: _compute_fields_for_operation

# 需要導入模塊: import types [as 別名]
# 或者: from types import BuiltinFunctionType [as 別名]
def _compute_fields_for_operation(self, fields, to_compute):
        row = OpRow(self)
        for name, tup in iteritems(fields):
            field, value = tup
            if isinstance(
                value,
                (
                    types.LambdaType,
                    types.FunctionType,
                    types.MethodType,
                    types.BuiltinFunctionType,
                    types.BuiltinMethodType,
                ),
            ):
                value = value()
            row.set_value(name, value, field)
        for name, field in to_compute:
            try:
                row.set_value(name, field.compute(row), field)
            except (KeyError, AttributeError):
                # error silently unless field is required!
                if field.required and name not in fields:
                    raise RuntimeError("unable to compute required field: %s" % name)
        return row 
開發者ID:web2py,項目名稱:pydal,代碼行數:26,代碼來源:objects.py

示例11: short_repr

# 需要導入模塊: import types [as 別名]
# 或者: from types import BuiltinFunctionType [as 別名]
def short_repr(obj):
    if isinstance(obj, (type, types.ModuleType, types.BuiltinMethodType,
                        types.BuiltinFunctionType)):
        return obj.__name__
    if isinstance(obj, types.MethodType):
        if obj.im_self is not None:
            return obj.im_func.__name__ + ' (bound)'
        else:
            return obj.im_func.__name__
    if isinstance(obj, (tuple, list, dict, set)):
        return '%d items' % len(obj)
    if isinstance(obj, weakref.ref):
        return 'all_weakrefs_are_one'
    return repr(obj)[:40] 
開發者ID:sippy,項目名稱:rtp_cluster,代碼行數:16,代碼來源:objgraph.py

示例12: isbuiltin

# 需要導入模塊: import types [as 別名]
# 或者: from types import BuiltinFunctionType [as 別名]
def isbuiltin(object):
    """Return true if the object is a built-in function or method.

    Built-in functions and methods provide these attributes:
        __doc__         documentation string
        __name__        original name of this function or method
        __self__        instance to which a method is bound, or None"""
    return isinstance(object, types.BuiltinFunctionType) 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:10,代碼來源:inspect.py

示例13: validate_aggregation

# 需要導入模塊: import types [as 別名]
# 或者: from types import BuiltinFunctionType [as 別名]
def validate_aggregation(function):  # TODO: Recognize when need `reduce`
    if not isinstance(function,
                      (types.BuiltinFunctionType,
                       types.FunctionType,
                       types.LambdaType)):
        raise InvalidAggregationFunction("A function object is required.")

    if not (function.__code__.co_argcount >= 1):
        raise InvalidAggregationFunction("A function taking at least one argument is required") 
開發者ID:CodeReclaimers,項目名稱:neat-python,代碼行數:11,代碼來源:aggregations.py

示例14: validate_activation

# 需要導入模塊: import types [as 別名]
# 或者: from types import BuiltinFunctionType [as 別名]
def validate_activation(function):
    if not isinstance(function,
                      (types.BuiltinFunctionType,
                       types.FunctionType,
                       types.LambdaType)):
        raise InvalidActivationFunction("A function object is required.")

    if function.__code__.co_argcount != 1:  # avoid deprecated use of `inspect`
        raise InvalidActivationFunction("A single-argument function is required.") 
開發者ID:CodeReclaimers,項目名稱:neat-python,代碼行數:11,代碼來源:activations.py

示例15: __deepcopy__

# 需要導入模塊: import types [as 別名]
# 或者: from types import BuiltinFunctionType [as 別名]
def __deepcopy__(self, memo):
        retVal = self.__class__()
        memo[id(self)] = retVal

        for attr in dir(self):
            if not attr.startswith('_'):
                value = getattr(self, attr)
                if not isinstance(value, (types.BuiltinFunctionType, types.FunctionType, types.MethodType)):
                    setattr(retVal, attr, copy.deepcopy(value, memo))

        for key, value in self.items():
            retVal.__setitem__(key, copy.deepcopy(value, memo))

        return retVal 
開發者ID:vulscanteam,項目名稱:vulscan,代碼行數:16,代碼來源:datatype.py


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