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


Python pydoc.allmethods方法代碼示例

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


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

示例1: test_allmethods

# 需要導入模塊: import pydoc [as 別名]
# 或者: from pydoc import allmethods [as 別名]
def test_allmethods(self):
        # issue 17476: allmethods was no longer returning unbound methods.
        # This test is a bit fragile in the face of changes to object and type,
        # but I can't think of a better way to do it without duplicating the
        # logic of the function under test.

        class TestClass(object):
            def method_returning_true(self):
                return True

        # What we expect to get back: everything on object...
        expected = dict(vars(object))
        # ...plus our unbound method...
        expected['method_returning_true'] = TestClass.method_returning_true
        # ...but not the non-methods on object.
        del expected['__doc__']
        del expected['__class__']
        # inspect resolves descriptors on type into methods, but vars doesn't,
        # so we need to update __subclasshook__.
        expected['__subclasshook__'] = TestClass.__subclasshook__

        methods = pydoc.allmethods(TestClass)
        self.assertDictEqual(methods, expected) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:25,代碼來源:test_pydoc.py

示例2: test_allmethods

# 需要導入模塊: import pydoc [as 別名]
# 或者: from pydoc import allmethods [as 別名]
def test_allmethods(self):
        # issue 17476: allmethods was no longer returning unbound methods.
        # This test is a bit fragile in the face of changes to object and type,
        # but I can't think of a better way to do it without duplicating the
        # logic of the function under test.

        class TestClass(object):
            def method_returning_true(self):
                return True

        # What we expect to get back: everything on object...
        expected = dict(vars(object))
        # ...plus our unbound method...
        expected['method_returning_true'] = TestClass.method_returning_true
        # ...but not the non-methods on object.
        del expected['__doc__']
        del expected['__class__']
        # inspect resolves descriptors on type into methods, but vars doesn't,
        # so we need to update __subclasshook__ and __init_subclass__.
        expected['__subclasshook__'] = TestClass.__subclasshook__
        expected['__init_subclass__'] = TestClass.__init_subclass__

        methods = pydoc.allmethods(TestClass)
        self.assertDictEqual(methods, expected) 
開發者ID:bkerler,項目名稱:android_universal,代碼行數:26,代碼來源:test_pydoc.py

示例3: usage

# 需要導入模塊: import pydoc [as 別名]
# 或者: from pydoc import allmethods [as 別名]
def usage(obj, selfname='self'):
    import inspect
    str(obj) # In case it's lazy, this will load it.

    if not isinstance(obj, class_types):
        obj = obj.__class__

    print('%s supports the following operations:' % obj.__name__)
    for (name, method) in sorted(pydoc.allmethods(obj).items()):
        if name.startswith('_'): continue
        if getattr(method, '__deprecated__', False): continue

        args, varargs, varkw, defaults = inspect.getargspec(method)
        if (args and args[0]=='self' and
            (defaults is None or len(args)>len(defaults))):
            args = args[1:]
            name = '%s.%s' % (selfname, name)
        argspec = inspect.formatargspec(
            args, varargs, varkw, defaults)
        print(textwrap.fill('%s%s' % (name, argspec),
                            initial_indent='  - ',
                            subsequent_indent=' '*(len(name)+5)))

##########################################################################
# IDLE
########################################################################## 
開發者ID:rafasashi,項目名稱:razzy-spinner,代碼行數:28,代碼來源:util.py

示例4: usage

# 需要導入模塊: import pydoc [as 別名]
# 或者: from pydoc import allmethods [as 別名]
def usage(obj, selfname='self'):
    import inspect
    str(obj) # In case it's lazy, this will load it.

    if not isinstance(obj, (types.TypeType, types.ClassType)):
        obj = obj.__class__

    print '%s supports the following operations:' % obj.__name__
    for (name, method) in sorted(pydoc.allmethods(obj).items()):
        if name.startswith('_'): continue
        if getattr(method, '__deprecated__', False): continue

        args, varargs, varkw, defaults = inspect.getargspec(method)
        if (args and args[0]=='self' and
            (defaults is None or len(args)>len(defaults))):
            args = args[1:]
            name = '%s.%s' % (selfname, name)
        argspec = inspect.formatargspec(
            args, varargs, varkw, defaults)
        print textwrap.fill('%s%s' % (name, argspec),
                            initial_indent='  - ',
                            subsequent_indent=' '*(len(name)+5))

##########################################################################
# IDLE
########################################################################## 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:28,代碼來源:util.py

示例5: usage

# 需要導入模塊: import pydoc [as 別名]
# 或者: from pydoc import allmethods [as 別名]
def usage(obj, selfname='self'):
    str(obj)  # In case it's lazy, this will load it.

    if not isinstance(obj, class_types):
        obj = obj.__class__

    print('%s supports the following operations:' % obj.__name__)
    for (name, method) in sorted(pydoc.allmethods(obj).items()):
        if name.startswith('_'):
            continue
        if getattr(method, '__deprecated__', False):
            continue

        if sys.version_info[0] >= 3:
            getargspec = inspect.getfullargspec
        else:
            getargspec = inspect.getargspec
        args, varargs, varkw, defaults = getargspec(method)[:4]
        if (
            args
            and args[0] == 'self'
            and (defaults is None or len(args) > len(defaults))
        ):
            args = args[1:]
            name = '%s.%s' % (selfname, name)
        argspec = inspect.formatargspec(args, varargs, varkw, defaults)
        print(
            textwrap.fill(
                '%s%s' % (name, argspec),
                initial_indent='  - ',
                subsequent_indent=' ' * (len(name) + 5),
            )
        )


##########################################################################
# IDLE
########################################################################## 
開發者ID:V1EngineeringInc,項目名稱:V1EngineeringInc-Docs,代碼行數:40,代碼來源:util.py


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