diff options
author | Ethan Furman <ethan@stoneleaf.us> | 2013-09-25 14:14:41 (GMT) |
---|---|---|
committer | Ethan Furman <ethan@stoneleaf.us> | 2013-09-25 14:14:41 (GMT) |
commit | e03ea37a7bea48c46e6d96851f471db0f3c8e6e2 (patch) | |
tree | 7b3ac5ca8ed5b94a29a80400e24746788c0b9efb /Lib/test/test_inspect.py | |
parent | 7cba5fd267219d23aec97fad91d73bea77daf5e2 (diff) | |
download | cpython-e03ea37a7bea48c46e6d96851f471db0f3c8e6e2.zip cpython-e03ea37a7bea48c46e6d96851f471db0f3c8e6e2.tar.gz cpython-e03ea37a7bea48c46e6d96851f471db0f3c8e6e2.tar.bz2 |
Close #19030: improvements to inspect and Enum.
inspect.getmembers and inspect.classify_class_attrs now search the metaclass
mro for types.DynamicClassAttributes (what use to be called
enum._RouteClassAttributeToGetattr); in part this means that these two
functions no longer rely solely on dir().
Besides now returning more accurate information, these improvements also
allow a more helpful help() on Enum classes.
Diffstat (limited to 'Lib/test/test_inspect.py')
-rw-r--r-- | Lib/test/test_inspect.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index bcb7d8a..22c2be8 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -652,6 +652,14 @@ class TestClassesAndFunctions(unittest.TestCase): if isinstance(builtin, type): inspect.classify_class_attrs(builtin) + def test_classify_VirtualAttribute(self): + class VA: + @types.DynamicClassAttribute + def ham(self): + return 'eggs' + should_find = inspect.Attribute('ham', 'data', VA, VA.__dict__['ham']) + self.assertIn(should_find, inspect.classify_class_attrs(VA)) + def test_getmembers_descriptors(self): class A(object): dd = _BrokenDataDescriptor() @@ -695,6 +703,13 @@ class TestClassesAndFunctions(unittest.TestCase): self.assertIn(('f', b.f), inspect.getmembers(b)) self.assertIn(('f', b.f), inspect.getmembers(b, inspect.ismethod)) + def test_getmembers_VirtualAttribute(self): + class A: + @types.DynamicClassAttribute + def eggs(self): + return 'spam' + self.assertIn(('eggs', A.__dict__['eggs']), inspect.getmembers(A)) + _global_ref = object() class TestGetClosureVars(unittest.TestCase): @@ -1082,6 +1097,15 @@ class TestGetattrStatic(unittest.TestCase): self.assertEqual(inspect.getattr_static(Thing, 'x'), Thing.x) + 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']) + def test_inherited_classattribute(self): class Thing(object): x = object() |