This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: inspect.classify_class_attrs() misclassifies object.__new__()
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 3.3, Python 3.4, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: eric.snow, python-dev, tim.peters, yselivanov
Priority: normal Keywords: patch

Created on 2013-08-21 19:51 by eric.snow, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
inspect_classify_01.patch yselivanov, 2014-01-30 05:33 review
Messages (5)
msg195818 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2013-08-21 19:51
>>> 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.

             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"
                 kind = "data"
msg209704 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2014-01-30 05:33
Tim, Eric,
Please review the attached patch.
msg209817 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-01-31 19:39
New changeset c38f99554be4 by Yury Selivanov in branch 'default':
inspect.classify_class_attrs: Classify object.__new__ and __init__ correctly #18801
msg209818 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2014-01-31 19:40
Not sure if we need to backport this to older python versions
msg209819 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-01-31 19:42
New changeset d0f95094033d by Yury Selivanov in branch 'default':
NEWS: Add news item for #18801
Date User Action Args
2022-04-11 14:57:49adminsetgithub: 63001
2014-01-31 19:42:42python-devsetmessages: + msg209819
2014-01-31 19:40:58yselivanovsetstatus: open -> closed
resolution: fixed
2014-01-31 19:40:38yselivanovsetmessages: + msg209818
2014-01-31 19:39:32python-devsetnosy: + python-dev
messages: + msg209817
2014-01-30 05:33:35yselivanovsetfiles: + inspect_classify_01.patch

nosy: + yselivanov, tim.peters
messages: + msg209704

keywords: + patch
2013-08-21 19:51:34eric.snowcreate