當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。