inspect.classify_class_attrs: Classify object.__new__ and __init__ correctly #18801

This commit is contained in:
Yury Selivanov 2014-01-31 14:28:44 -05:00
parent 28479d8c7d
commit 0860a0bd3f
2 changed files with 5 additions and 1 deletions

View File

@ -412,7 +412,7 @@ def classify_class_attrs(cls):
elif isinstance(dict_obj, property):
kind = "property"
obj = dict_obj
elif isfunction(obj) or ismethoddescriptor(obj):
elif isroutine(obj):
kind = "method"
else:
kind = "data"

View File

@ -646,6 +646,10 @@ class TestClassesAndFunctions(unittest.TestCase):
md = _BrokenMethodDescriptor()
attrs = attrs_wo_objs(A)
self.assertIn(('__new__', 'method', object), attrs, 'missing __new__')
self.assertIn(('__init__', 'method', object), attrs, 'missing __init__')
self.assertIn(('s', 'static method', A), attrs, 'missing static method')
self.assertIn(('c', 'class method', A), attrs, 'missing class method')
self.assertIn(('p', 'property', A), attrs, 'missing property')