当前位置: 首页>>代码示例>>Python>>正文


Python inspect.ismethoddescriptor方法代码示例

本文整理汇总了Python中inspect.ismethoddescriptor方法的典型用法代码示例。如果您正苦于以下问题:Python inspect.ismethoddescriptor方法的具体用法?Python inspect.ismethoddescriptor怎么用?Python inspect.ismethoddescriptor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在inspect的用法示例。


在下文中一共展示了inspect.ismethoddescriptor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_func_args

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethoddescriptor [as 别名]
def get_func_args(func, stripself=False):
    """Return the argument name list of a callable"""
    if inspect.isfunction(func):
        func_args, _, _, _ = _getargspec_py23(func)
    elif inspect.isclass(func):
        return get_func_args(func.__init__, True)
    elif inspect.ismethod(func):
        return get_func_args(func.__func__, True)
    elif inspect.ismethoddescriptor(func):
        return []
    elif isinstance(func, partial):
        return [x for x in get_func_args(func.func)[len(func.args):]
                if not (func.keywords and x in func.keywords)]
    elif hasattr(func, '__call__'):
        if inspect.isroutine(func):
            return []
        elif getattr(func, '__name__', None) == '__call__':
            return []
        else:
            return get_func_args(func.__call__, True)
    else:
        raise TypeError('%s is not callable' % type(func))
    if stripself:
        func_args.pop(0)
    return func_args 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:27,代码来源:python.py

示例2: isfunc

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethoddescriptor [as 别名]
def isfunc(mod, f):
	assert hasattr(mod, f)
	attr = getattr(mod, f)

	#Ignore functions like _add
	if (len(f) >= 2):
		if f[0] == "_" and f[1] != "_":
			return False

	#Ignore functions from this list
	ignore = ['__all__', '__array__', '__array_priority__', '__array_wrap__', '__bool__', '__builtins__', '__cached__', '__class__', '__deepcopy__', '__delattr__', '__delitem__', '__dict__', '__dir__', '__doc__', '__file__', '__format__', '__getattribute__', '__getitem__', '__hash__', '__index__', '__init__', '__init_subclass__', '__iter__', '__len__', '__loader__', '__module__', '__name__', '__new__', '__nonzero__', '__package__', '__path__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__setattr__', '__setitem__', '__setstate__', '__sizeof__', '__spec__', '__str__', '__subclasshook__', '__version__', '__weakref__']

	#Add functions to this list if they cause recursion
	ignore += ['size', 'tolist', 'dim', 'is_storage', 'item']
	if f in ignore:
		return False

	return ins.ismethod(attr) or ins.isfunction(attr) or ins.ismethoddescriptor(attr) or ins.isbuiltin(attr) 
开发者ID:adityaiitb,项目名称:pyprof2,代码行数:20,代码来源:nvmarker.py

示例3: default

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethoddescriptor [as 别名]
def default(self, obj):
        if isinstance(obj, datetime):
            return obj.isoformat() + 'Z'
        if hasattr(obj, "to_json"):
            return self.default(obj.to_json())
        elif hasattr(obj, "__dict__"):
            d = dict(
                (key, value)
                for key, value in inspect.getmembers(obj)
                if not key.startswith("_")
                and not inspect.isabstract(value)
                and not inspect.isbuiltin(value)
                and not inspect.isfunction(value)
                and not inspect.isgenerator(value)
                and not inspect.isgeneratorfunction(value)
                and not inspect.ismethod(value)
                and not inspect.ismethoddescriptor(value)
                and not inspect.isroutine(value)
            )
            return self.default(d)
        return obj 
开发者ID:Ermlab,项目名称:python-ddd,代码行数:23,代码来源:response.py

示例4: format_args

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethoddescriptor [as 别名]
def format_args(self):
        if inspect.isbuiltin(self.object) or \
               inspect.ismethoddescriptor(self.object):
            # can never get arguments of a C function or method unless
            # a function to do so is supplied
            if self.env.config.autodoc_builtin_argspec:
                argspec = self.env.config.autodoc_builtin_argspec(self.object)
                return inspect.formatargspec(*argspec)
            else:
                return None
        try:
            argspec = inspect.getargspec(self.object)
        except TypeError:
            # if a class should be documented as function (yay duck
            # typing) we try to use the constructor signature as function
            # signature without the first argument.
            try:
                argspec = inspect.getargspec(self.object.__new__)
            except TypeError:
                argspec = inspect.getargspec(self.object.__init__)
                if argspec[0]:
                    del argspec[0][0]
        return inspect.formatargspec(*argspec) 
开发者ID:cihologramas,项目名称:pyoptools,代码行数:25,代码来源:sage_autodoc.py

示例5: getMethods

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethoddescriptor [as 别名]
def getMethods(self, object, class_name):
        try:
            key = "%s:%s" % (self.module_name, class_name)
            blacklist = BLACKLIST[key]
        except KeyError:
            blacklist = set()
        methods = []
        for name in dir(object):
            if name in blacklist:
                continue
            if SKIP_PRIVATE and name.startswith("__"):
                continue
            attr = getattr(object, name)
            if not ismethoddescriptor(attr):
                continue
            methods.append(name)
        return methods 
开发者ID:tuwid,项目名称:darkc0de-old-stuff,代码行数:19,代码来源:python.py

示例6: auto_override_class

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethoddescriptor [as 别名]
def auto_override_class(cls, force = False, force_recursive = False):
    """Works like auto_override, but is only applicable to classes.
    """
    if not pytypes.checking_enabled:
        return cls
    assert(isclass(cls))
    if not force and is_no_type_check(cls):
        return cls
    # To play it safe we avoid to modify the dict while iterating over it,
    # so we previously cache keys.
    # For this we don't use keys() because of Python 3.
    # Todo: Better use inspect.getmembers here
    keys = [key for key in cls.__dict__]
    for key in keys:
        memb = cls.__dict__[key]
        if force_recursive or not is_no_type_check(memb):
            if isfunction(memb) or ismethod(memb) or ismethoddescriptor(memb):
                if util._has_base_method(memb, cls):
                    setattr(cls, key, override(memb))
            elif isclass(memb):
                auto_override_class(memb, force_recursive, force_recursive)
    return cls 
开发者ID:Stewori,项目名称:pytypes,代码行数:24,代码来源:typechecker.py

示例7: _is_some_method

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethoddescriptor [as 别名]
def _is_some_method(obj):
    return (inspect.isfunction(obj) or
            inspect.ismethod(obj) or
            inspect.isbuiltin(obj) or
            inspect.ismethoddescriptor(obj)) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:7,代码来源:pydoc.py

示例8: _is_some_method

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethoddescriptor [as 别名]
def _is_some_method(obj):
    return inspect.ismethod(obj) or inspect.ismethoddescriptor(obj) 
开发者ID:glmcdona,项目名称:meddle,代码行数:4,代码来源:pydoc.py

示例9: test_ipy3_gh230

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethoddescriptor [as 别名]
def test_ipy3_gh230(self):
        """https://github.com/IronLanguages/ironpython3/pull/230"""
        import inspect
        class test(object): pass

        self.assertFalse(inspect.ismethoddescriptor(test.__weakref__))
        self.assertFalse(inspect.ismethoddescriptor(test.__dict__["__dict__"])) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_regressions.py

示例10: _which_methods_should_we_auto_overload

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethoddescriptor [as 别名]
def _which_methods_should_we_auto_overload(self, tensor_type: type):
        """Creates a list of Torch methods to auto overload.

        By default, it looks for the intersection between the methods of
        tensor_type and torch_type minus those in the exception list
        (syft.torch.exclude).

        Args:
            tensor_type: Iterate through the properties of this tensor type.
            syft_type: Iterate through all attributes in this type.

        Returns:
            A list of methods to be overloaded.
        """

        to_overload = self.boolean_comparators.copy()

        native_pattern = re.compile("native*")

        for attr in dir(tensor_type):

            # Conditions for not overloading the method
            # TODO[jvmancuso] separate func exclusion from method exclusion
            if attr in syft.framework.exclude:
                continue
            if not hasattr(tensor_type, attr):
                continue

            lit = getattr(tensor_type, attr)
            is_base = attr in dir(object)
            is_desc = inspect.ismethoddescriptor(lit)
            is_func = isinstance(lit, types.FunctionType)
            is_overloaded = native_pattern.match(attr) is not None

            if (is_desc or is_func) and not is_base and not is_overloaded:
                to_overload.append(attr)

        return set(to_overload) 
开发者ID:OpenMined,项目名称:PySyft,代码行数:40,代码来源:tensors.py

示例11: _from_module

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethoddescriptor [as 别名]
def _from_module(self, module, object):
        """
        Return true if the given object is defined in the given
        module.
        """
        if module is None:
            return True
        elif inspect.isfunction(object):
            return module.__dict__ is object.func_globals
        elif inspect.isbuiltin(object):
            return module.__name__ == object.__module__
        elif inspect.isclass(object):
            return module.__name__ == object.__module__
        elif inspect.ismethod(object):
            # This one may be a bug in cython that fails to correctly set the
            # __module__ attribute of methods, but since the same error is easy
            # to make by extension code writers, having this safety in place
            # isn't such a bad idea
            return module.__name__ == object.im_class.__module__
        elif inspect.getmodule(object) is not None:
            return module is inspect.getmodule(object)
        elif hasattr(object, '__module__'):
            return module.__name__ == object.__module__
        elif isinstance(object, property):
            return True # [XX] no way not be sure.
        elif inspect.ismethoddescriptor(object):
            # Unbound PyQt signals reach this point in Python 3.4b3, and we want
            # to avoid throwing an error. See also http://bugs.python.org/issue3158
            return False
        else:
            raise ValueError("object must be a class or function") 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:33,代码来源:ipdoctest.py

示例12: type

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethoddescriptor [as 别名]
def type(self):
        cls = self._cls().obj
        if inspect.isclass(cls):
            return 'class'
        elif inspect.ismodule(cls):
            return 'module'
        elif inspect.isbuiltin(cls) or inspect.ismethod(cls) \
                or inspect.ismethoddescriptor(cls):
            return 'function' 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:11,代码来源:__init__.py

示例13: is_class_instance

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethoddescriptor [as 别名]
def is_class_instance(obj):
    """Like inspect.* methods."""
    return not (inspect.isclass(obj) or inspect.ismodule(obj)
                or inspect.isbuiltin(obj) or inspect.ismethod(obj)
                or inspect.ismethoddescriptor(obj) or inspect.iscode(obj)
                or inspect.isgenerator(obj)) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:8,代码来源:fake.py

示例14: __init__

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethoddescriptor [as 别名]
def __init__(self, clazz, object, dispatcher):
        self.clazz = clazz
        self.object = object
        self.dispatcher = dispatcher

    # XXX: This is here for inspect.ismethoddescriptor which needs to
    # return True for help() to work properly. There may be a better
    # way to do this. 
开发者ID:datawire,项目名称:forge,代码行数:10,代码来源:match.py

示例15: set_doc

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethoddescriptor [as 别名]
def set_doc(obj, docstring):
    if ((inspect.ismethoddescriptor(obj) or inspect.isroutine(obj))
            and not inspect.isfunction(obj)):
        # pybind-generated functions and methods
        _core._set_pybind_doc(obj, docstring)
        return

    obj.__doc__ = docstring 
开发者ID:chainer,项目名称:chainer,代码行数:10,代码来源:__init__.py


注:本文中的inspect.ismethoddescriptor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。