Python types.BuiltinFunctionType() Examples
The following are 30
code examples of types.BuiltinFunctionType().
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
types
, or try the search function
.
Example #1
Source File: moduledump.py From pythonista-scripts with MIT License | 6 votes |
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)
Example #2
Source File: utils.py From lark with MIT License | 6 votes |
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)
Example #3
Source File: api.py From SwiftKitten with MIT License | 6 votes |
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))
Example #4
Source File: api.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
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))
Example #5
Source File: codecs.py From delira with GNU Affero General Public License v3.0 | 6 votes |
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"])
Example #6
Source File: sage_autodoc.py From pyoptools with GNU General Public License v3.0 | 6 votes |
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
Example #7
Source File: api.py From scalyr-agent-2 with Apache License 2.0 | 6 votes |
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))
Example #8
Source File: api.py From oss-ftp with MIT License | 6 votes |
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))
Example #9
Source File: json_parser.py From lark with MIT License | 6 votes |
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)
Example #10
Source File: api.py From learn_python3_spider with MIT License | 6 votes |
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))
Example #11
Source File: api.py From bioforum with MIT License | 6 votes |
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))
Example #12
Source File: api.py From learn_python3_spider with MIT License | 6 votes |
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))
Example #13
Source File: objgraph.py From exaddos with BSD 3-Clause "New" or "Revised" License | 6 votes |
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]
Example #14
Source File: enforce.py From CrossHair with MIT License | 6 votes |
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
Example #15
Source File: moduledump.py From pythonista-scripts with MIT License | 6 votes |
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())
Example #16
Source File: api.py From teleport with Apache License 2.0 | 6 votes |
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))
Example #17
Source File: api.py From teleport with Apache License 2.0 | 6 votes |
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))
Example #18
Source File: objects.py From pydal with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #19
Source File: api.py From quickstart-git2s3 with Apache License 2.0 | 6 votes |
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))
Example #20
Source File: grads.py From tangent with Apache License 2.0 | 6 votes |
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
Example #21
Source File: api.py From quickstart-git2s3 with Apache License 2.0 | 6 votes |
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))
Example #22
Source File: datatype.py From ZEROScan with MIT License | 5 votes |
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
Example #23
Source File: reflection.py From appkernel with Apache License 2.0 | 5 votes |
def is_function(obj): """Returns true if passed a function >>> is_function(lambda x: 1) True >>> is_function(locals) True >>> def method(): pass >>> is_function(method) True >>> is_function(1) False """ if type(obj) in (types.FunctionType, types.MethodType, types.LambdaType, types.BuiltinFunctionType, types.BuiltinMethodType): return True if not hasattr(obj, '__class__'): return False module = translate_module_name(obj.__class__.__module__) name = obj.__class__.__name__ return (module == '__builtin__' and name in ('function', 'builtin_function_or_method', 'instancemethod', 'method-wrapper'))
Example #24
Source File: visualstudio_py_repl.py From iot-utilities with BSD 3-Clause "New" or "Revised" License | 5 votes |
def collect_signatures(self, val): doc = val.__doc__ type_obj = None if isinstance(val, type) or isinstance(val, _OldClassType): type_obj = val val = val.__init__ try: args, vargs, varkw, defaults = inspect.getargspec(val) except TypeError: # we're not doing inspect on a Python function... if sys.platform == 'cli': if type_obj is not None: clr_type = clr.GetClrType(type_obj) ctors = clr_type.GetConstructors() return [self.get_ipy_sig(type_obj, ctor) for ctor in ctors] elif type(val) is types.BuiltinFunctionType: return [self.get_ipy_sig(target, target.Targets[0]) for target in val.Overloads.Functions] elif type(val) is builtin_method_descriptor_type: val = PythonOps.GetBuiltinMethodDescriptorTemplate(val) return [self.get_ipy_sig(target, target.Targets[0]) for target in val.Overloads.Functions] raise remove_self = type_obj is not None or (type(val) is types.MethodType and ((sys.version_info >= (3,) and val.__self__ is not None) or (sys.version_info < (3,) and val.im_self is not None))) if remove_self: # remove self for instance methods and types args = args[1:] if defaults is not None: defaults = [repr(default) for default in defaults] else: defaults = [] return [(doc, args, vargs, varkw, defaults)]
Example #25
Source File: base.py From addon with GNU General Public License v3.0 | 5 votes |
def py_wrap(py): if isinstance(py, (FunctionType, BuiltinFunctionType, MethodType, BuiltinMethodType, dict, int, str, bool, float, list, tuple, long, basestring)) or py is None: return HJs(py) return PyObjectWrapper(py) ############################################################################## #Define types #Object
Example #26
Source File: inspect.py From ironpython3 with Apache License 2.0 | 5 votes |
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)
Example #27
Source File: datatype.py From w9scan with GNU General Public License v2.0 | 5 votes |
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
Example #28
Source File: inspect.py From Imogen with MIT License | 5 votes |
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)
Example #29
Source File: visualstudio_py_repl.py From iot-utilities with BSD 3-Clause "New" or "Revised" License | 5 votes |
def collect_signatures(self, val): doc = val.__doc__ type_obj = None if isinstance(val, type) or isinstance(val, _OldClassType): type_obj = val val = val.__init__ try: args, vargs, varkw, defaults = inspect.getargspec(val) except TypeError: # we're not doing inspect on a Python function... if sys.platform == 'cli': if type_obj is not None: clr_type = clr.GetClrType(type_obj) ctors = clr_type.GetConstructors() return [self.get_ipy_sig(type_obj, ctor) for ctor in ctors] elif type(val) is types.BuiltinFunctionType: return [self.get_ipy_sig(target, target.Targets[0]) for target in val.Overloads.Functions] elif type(val) is builtin_method_descriptor_type: val = PythonOps.GetBuiltinMethodDescriptorTemplate(val) return [self.get_ipy_sig(target, target.Targets[0]) for target in val.Overloads.Functions] raise remove_self = type_obj is not None or (type(val) is types.MethodType and ((sys.version_info >= (3,) and val.__self__ is not None) or (sys.version_info < (3,) and val.im_self is not None))) if remove_self: # remove self for instance methods and types args = args[1:] if defaults is not None: defaults = [repr(default) for default in defaults] else: defaults = [] return [(doc, args, vargs, varkw, defaults)]
Example #30
Source File: rna_info.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def get_py_c_functions(self): import types functions = [] for identifier, attr in self._get_py_visible_attrs(): # methods may be python wrappers to C functions attr_func = getattr(attr, "__func__", attr) if type(attr_func) in {types.BuiltinMethodType, types.BuiltinFunctionType}: functions.append((identifier, attr)) return functions