当前位置: 首页>>代码示例>>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;未经允许,请勿转载。