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 <[email protected]>
<http://bugs.python.org/issue18801>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com