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


Python inspect.getattr_static方法代码示例

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


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

示例1: test_metaclass

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getattr_static [as 别名]
def test_metaclass(self):
        class meta(type):
            attr = 'foo'
        class Thing(object, metaclass=meta):
            pass
        self.assertEqual(inspect.getattr_static(Thing, 'attr'), 'foo')

        class sub(meta):
            pass
        class OtherThing(object, metaclass=sub):
            x = 3
        self.assertEqual(inspect.getattr_static(OtherThing, 'attr'), 'foo')

        class OtherOtherThing(OtherThing):
            pass
        # this test is odd, but it was added as it exposed a bug
        self.assertEqual(inspect.getattr_static(OtherOtherThing, 'x'), 3) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:test_inspect.py

示例2: test_descriptor

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getattr_static [as 别名]
def test_descriptor(self):
        class descriptor(object):
            def __get__(self, instance, owner):
                return 3
        class Foo(object):
            d = descriptor()

        foo = Foo()

        # for a non data descriptor we return the instance attribute
        foo.__dict__['d'] = 1
        self.assertEqual(inspect.getattr_static(foo, 'd'), 1)

        # if the descriptor is a data-desciptor we should return the
        # descriptor
        descriptor.__set__ = lambda s, i, v: None
        self.assertEqual(inspect.getattr_static(foo, 'd'), Foo.__dict__['d']) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:test_inspect.py

示例3: test_metaclass_with_metaclass_with_dict_as_property

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getattr_static [as 别名]
def test_metaclass_with_metaclass_with_dict_as_property(self):
        class MetaMeta(type):
            @property
            def __dict__(self):
                self.executed = True
                return dict(spam=42)

        class Meta(type, metaclass=MetaMeta):
            executed = False

        class Thing(metaclass=Meta):
            pass

        with self.assertRaises(AttributeError):
            inspect.getattr_static(Thing, "spam")
        self.assertFalse(Thing.executed) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:18,代码来源:test_inspect.py

示例4: _property_names

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getattr_static [as 别名]
def _property_names(self):
        """Return a set of the names of the properties defined on the model."""
        names = []
        for name in dir(self.model):
            attr = inspect.getattr_static(self.model, name)
            if isinstance(attr, property):
                names.append(name)
        return frozenset(names) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:10,代码来源:options.py

示例5: test_basic

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getattr_static [as 别名]
def test_basic(self):
        class Thing(object):
            x = object()

        thing = Thing()
        self.assertEqual(inspect.getattr_static(thing, 'x'), Thing.x)
        self.assertEqual(inspect.getattr_static(thing, 'x', None), Thing.x)
        with self.assertRaises(AttributeError):
            inspect.getattr_static(thing, 'y')

        self.assertEqual(inspect.getattr_static(thing, 'y', 3), 3) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:13,代码来源:test_inspect.py

示例6: test_inherited

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getattr_static [as 别名]
def test_inherited(self):
        class Thing(object):
            x = object()
        class OtherThing(Thing):
            pass

        something = OtherThing()
        self.assertEqual(inspect.getattr_static(something, 'x'), Thing.x) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_inspect.py

示例7: test_instance_attr

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getattr_static [as 别名]
def test_instance_attr(self):
        class Thing(object):
            x = 2
            def __init__(self, x):
                self.x = x
        thing = Thing(3)
        self.assertEqual(inspect.getattr_static(thing, 'x'), 3)
        del thing.x
        self.assertEqual(inspect.getattr_static(thing, 'x'), 2) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_inspect.py

示例8: test_property

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getattr_static [as 别名]
def test_property(self):
        class Thing(object):
            @property
            def x(self):
                raise AttributeError("I'm pretending not to exist")
        thing = Thing()
        self.assertEqual(inspect.getattr_static(thing, 'x'), Thing.x) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:9,代码来源:test_inspect.py

示例9: test_descriptor_raises_AttributeError

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getattr_static [as 别名]
def test_descriptor_raises_AttributeError(self):
        class descriptor(object):
            def __get__(*_):
                raise AttributeError("I'm pretending not to exist")
        desc = descriptor()
        class Thing(object):
            x = desc
        thing = Thing()
        self.assertEqual(inspect.getattr_static(thing, 'x'), desc) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_inspect.py

示例10: test_classVirtualAttribute

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getattr_static [as 别名]
def test_classVirtualAttribute(self):
        class Thing(object):
            @types.DynamicClassAttribute
            def x(self):
                return self._x
            _x = object()

        self.assertEqual(inspect.getattr_static(Thing, 'x'), Thing.__dict__['x']) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_inspect.py

示例11: test_inherited_classattribute

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getattr_static [as 别名]
def test_inherited_classattribute(self):
        class Thing(object):
            x = object()
        class OtherThing(Thing):
            pass

        self.assertEqual(inspect.getattr_static(OtherThing, 'x'), Thing.x) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:9,代码来源:test_inspect.py

示例12: test_slots

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getattr_static [as 别名]
def test_slots(self):
        class Thing(object):
            y = 'bar'
            __slots__ = ['x']
            def __init__(self):
                self.x = 'foo'
        thing = Thing()
        self.assertEqual(inspect.getattr_static(thing, 'x'), Thing.x)
        self.assertEqual(inspect.getattr_static(thing, 'y'), 'bar')

        del thing.x
        self.assertEqual(inspect.getattr_static(thing, 'x'), Thing.x) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:14,代码来源:test_inspect.py

示例13: test_no_dict_no_slots

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getattr_static [as 别名]
def test_no_dict_no_slots(self):
        self.assertEqual(inspect.getattr_static(1, 'foo', None), None)
        self.assertNotEqual(inspect.getattr_static('foo', 'lower'), None) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_inspect.py

示例14: test_inherited_slots

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getattr_static [as 别名]
def test_inherited_slots(self):
        # returns descriptor
        class Thing(object):
            __slots__ = ['x']
            def __init__(self):
                self.x = 'foo'

        class OtherThing(Thing):
            pass
        # it would be nice if this worked...
        # we get the descriptor instead of the instance attribute
        self.assertEqual(inspect.getattr_static(OtherThing(), 'x'), Thing.x) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:14,代码来源:test_inspect.py

示例15: test_metaclass_with_descriptor

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import getattr_static [as 别名]
def test_metaclass_with_descriptor(self):
        class descriptor(object):
            def __get__(self, instance, owner):
                return 3
        class meta(type):
            d = descriptor()
        class Thing(object, metaclass=meta):
            pass
        self.assertEqual(inspect.getattr_static(Thing, 'd'), meta.__dict__['d']) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_inspect.py


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