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


Python inspect.classify_class_attrs方法代碼示例

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


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

示例1: _generate_attrs

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import classify_class_attrs [as 別名]
def _generate_attrs(self):
        """Get detailed info about target object.

        Uses ``inspect.classify_class_attrs`` to get several important details about each attribute
        on the target object.

        :return: The attribute details dict.
        :rtype: dict
        """
        attrs = {}

        if ismodule(self.doubled_obj):
            for name, func in getmembers(self.doubled_obj, is_callable):
                attrs[name] = Attribute(func, 'toplevel', self.doubled_obj)
        else:
            for attr in classify_class_attrs(self.doubled_obj_type):
                attrs[attr.name] = attr

        return attrs 
開發者ID:uber,項目名稱:doubles,代碼行數:21,代碼來源:target.py

示例2: classify_class_attrs

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import classify_class_attrs [as 別名]
def classify_class_attrs(object):
    """Wrap inspect.classify_class_attrs, with fixup for data descriptors."""
    results = []
    for (name, kind, cls, value) in inspect.classify_class_attrs(object):
        if inspect.isdatadescriptor(value):
            kind = 'data descriptor'
        results.append((name, kind, cls, value))
    return results

# ----------------------------------------------------- module manipulation 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:12,代碼來源:pydoc.py

示例3: classify_class_attrs

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import classify_class_attrs [as 別名]
def classify_class_attrs(object):
    """Wrap inspect.classify_class_attrs, with fixup for data descriptors."""
    def fixup(data):
        name, kind, cls, value = data
        if inspect.isdatadescriptor(value):
            kind = 'data descriptor'
        return name, kind, cls, value
    return map(fixup, inspect.classify_class_attrs(object))

# ----------------------------------------------------- module manipulation 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:12,代碼來源:pydoc.py

示例4: classify_class_attrs

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import classify_class_attrs [as 別名]
def classify_class_attrs(object):
    """Wrap inspect.classify_class_attrs, with fixup for data descriptors."""
    def fixup(data):
        name, kind, cls, value = data
        if inspect.isdatadescriptor(value):
            kind = 'data descriptor'
        return name, kind, cls, value
    return map(fixup, inspect.classify_class_attrs(object))

# ----------------------------------------------------- Unicode support helpers 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:12,代碼來源:pydoc.py

示例5: __getattr__

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import classify_class_attrs [as 別名]
def __getattr__(*args):
        raise AssertionError("should not __getattr__ method descriptors")


# Helper for testing classify_class_attrs. 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,代碼來源:test_inspect.py

示例6: attrs_wo_objs

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import classify_class_attrs [as 別名]
def attrs_wo_objs(cls):
    return [t[:3] for t in inspect.classify_class_attrs(cls)] 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:4,代碼來源:test_inspect.py

示例7: test_classify_oldstyle

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import classify_class_attrs [as 別名]
def test_classify_oldstyle(self):
        """classify_class_attrs finds static methods, class methods,
        properties, normal methods, and data attributes on an old-style
        class.
        """
        self._classify_test(False) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:8,代碼來源:test_inspect.py

示例8: test_classify_builtin_types

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import classify_class_attrs [as 別名]
def test_classify_builtin_types(self):
        # Simple sanity check that all built-in types can have their
        # attributes classified.
        for name in dir(__builtin__):
            builtin = getattr(__builtin__, name)
            if isinstance(builtin, type):
                inspect.classify_class_attrs(builtin) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:9,代碼來源:test_inspect.py

示例9: get_init_doc

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import classify_class_attrs [as 別名]
def get_init_doc(klass):
    for attr in inspect.classify_class_attrs(klass):
        if attr.name == '__init__':
            if attr.defining_class is klass:
                return attr.object.__doc__
            else:
                # Ignore __init__ method inherited from a super class
                return None
    return None 
開發者ID:chainer,項目名稱:chainer,代碼行數:11,代碼來源:test_init_docstring.py

示例10: test_inspect_classify_class_attrs

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import classify_class_attrs [as 別名]
def test_inspect_classify_class_attrs(self):
        # indirectly test __objclass__
        from inspect import Attribute
        values = [
                Attribute(name='__class__', kind='data',
                    defining_class=object, object=EnumMeta),
                Attribute(name='__doc__', kind='data',
                    defining_class=self.Color, object='An enumeration.'),
                Attribute(name='__members__', kind='property',
                    defining_class=EnumMeta, object=EnumMeta.__members__),
                Attribute(name='__module__', kind='data',
                    defining_class=self.Color, object=__name__),
                Attribute(name='blue', kind='data',
                    defining_class=self.Color, object=self.Color.blue),
                Attribute(name='green', kind='data',
                    defining_class=self.Color, object=self.Color.green),
                Attribute(name='red', kind='data',
                    defining_class=self.Color, object=self.Color.red),
                Attribute(name='name', kind='data',
                    defining_class=Enum, object=Enum.__dict__['name']),
                Attribute(name='value', kind='data',
                    defining_class=Enum, object=Enum.__dict__['value']),
                ]
        values.sort(key=lambda item: item.name)
        result = list(inspect.classify_class_attrs(self.Color))
        result.sort(key=lambda item: item.name)
        failed = False
        for v, r in zip(values, result):
            if r != v:
                print('\n%s\n%s\n%s\n%s\n' % ('=' * 75, r, v, '=' * 75), sep='')
                failed = True
        if failed:
            self.fail("result does not equal expected, see print above") 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:35,代碼來源:test_enum.py

示例11: __getattr__

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import classify_class_attrs [as 別名]
def __getattr__(*args):
        raise AttributeError("broken method descriptor")


# Helper for testing classify_class_attrs. 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:7,代碼來源:test_inspect.py

示例12: test_classify_builtin_types

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import classify_class_attrs [as 別名]
def test_classify_builtin_types(self):
        # Simple sanity check that all built-in types can have their
        # attributes classified.
        for name in dir(__builtins__):
            builtin = getattr(__builtins__, name)
            if isinstance(builtin, type):
                inspect.classify_class_attrs(builtin) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:9,代碼來源:test_inspect.py

示例13: test_classify_overrides_bool

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import classify_class_attrs [as 別名]
def test_classify_overrides_bool(self):
        class NoBool(object):
            def __eq__(self, other):
                return NoBool()

            def __bool__(self):
                raise NotImplementedError(
                    "This object does not specify a boolean value")

        class HasNB(object):
            dd = NoBool()

        should_find_attr = inspect.Attribute('dd', 'data', HasNB, HasNB.dd)
        self.assertIn(should_find_attr, inspect.classify_class_attrs(HasNB)) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:16,代碼來源:test_inspect.py

示例14: test_classify_metaclass_class_attribute

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import classify_class_attrs [as 別名]
def test_classify_metaclass_class_attribute(self):
        class Meta(type):
            fish = 'slap'
            def __dir__(self):
                return ['__class__', '__module__', '__name__', 'fish']
        class Class(metaclass=Meta):
            pass
        should_find = inspect.Attribute('fish', 'data', Meta, 'slap')
        self.assertIn(should_find, inspect.classify_class_attrs(Class)) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:11,代碼來源:test_inspect.py

示例15: test_classify_VirtualAttribute

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import classify_class_attrs [as 別名]
def test_classify_VirtualAttribute(self):
        class Meta(type):
            def __dir__(cls):
                return ['__class__', '__module__', '__name__', 'BOOM']
            def __getattr__(self, name):
                if name =='BOOM':
                    return 42
                return super().__getattr(name)
        class Class(metaclass=Meta):
            pass
        should_find = inspect.Attribute('BOOM', 'data', Meta, 42)
        self.assertIn(should_find, inspect.classify_class_attrs(Class)) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:14,代碼來源:test_inspect.py


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