[New-bugs-announce] [issue18801] inspect.classify_class_attrs() misclassifies object.__new__()
Eric Snow
report at bugs.python.org
Wed Aug 21 21:51:34 CEST 2013
New submission from Eric Snow:
>>> pprint.pprint(inspect.classify_class_attrs(object))
[Attribute(name='__class__', kind='data', defining_class=<class 'object'>, object=<attribute '__class__' of 'object' objects>),
...
Attribute(name='__init__', kind='method', defining_class=<class 'object'>, object=<slot wrapper '__init__' of 'object' objects>),
...
Attribute(name='__new__', kind='data', defining_class=<class 'object'>, object=<built-in method __new__ of type object at 0x8aee20>),
...
]
I haven't had a chance to look into why __new__() falls through the cracks but expect it's due to how __new__() is treated like a staticmethod without being one. I suppose there could be other similar cases, but __new__() is probably the only oddball here.
An extra test using isbuiltin() fixes this.
else:
obj_via_getattr = getattr(cls, name)
if (ismethod(obj_via_getattr) or
- ismethoddescriptor(obj_via_getattr)):
+ ismethoddescriptor(obj_via_getattr) or
+ isbuiltin(obj_via_getattr)):
kind = "method"
else:
kind = "data"
----------
components: Library (Lib)
messages: 195818
nosy: eric.snow
priority: normal
severity: normal
stage: test needed
status: open
title: inspect.classify_class_attrs() misclassifies object.__new__()
type: behavior
versions: Python 2.7, Python 3.3, Python 3.4
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18801>
_______________________________________
More information about the New-bugs-announce
mailing list