New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"inspect" gets broken by some descriptors #46118
Comments
The inspect functions "getmembers(cls)" and "classify_class_attrs(cls)" The bug affects 'pydoc' and the built in 'help' (which is in fact |
Please submit a patch. |
In "dm.zdoc" (a "pydoc" wrapper for Zope) I simply filter out all names |
This is my attempt at a patch for this. It fixes inspect.getmembers and As for pydoc, things look a bit more complicated... The annoying thing |
For the record the same problem also happens with toscawidgets. >>> from toscawidgets.widgets.forms import validators
>>> help(validators)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/site.py", line 351, in __call__
return pydoc.help(*args, **kwds)
File "/usr/lib/python2.5/pydoc.py", line 1646, in __call__
self.help(request)
File "/usr/lib/python2.5/pydoc.py", line 1690, in help
else: doc(request, 'Help on %s:')
File "/usr/lib/python2.5/pydoc.py", line 1481, in doc
pager(title % desc + '\n\n' + text.document(object, name))
File "/usr/lib/python2.5/pydoc.py", line 324, in document
if inspect.ismodule(object): return self.docmodule(*args)
File "/usr/lib/python2.5/pydoc.py", line 1072, in docmodule
contents.append(self.document(value, key, name))
File "/usr/lib/python2.5/pydoc.py", line 325, in document
if inspect.isclass(object): return self.docclass(*args)
File "/usr/lib/python2.5/pydoc.py", line 1173, in docclass
classify_class_attrs(object))
File "/usr/lib/python2.5/pydoc.py", line 179, in classify_class_attrs
return map(fixup, inspect.classify_class_attrs(object))
File "/usr/lib/python2.5/inspect.py", line 246, in classify_class_attrs
obj = getattr(cls, name)
File
"/usr/lib/python2.5/site-packages/FormEncode-0.7.1-py2.5.egg/formencode/declarative.py",
line 105, in __get__
obj = type.singleton()
File
"/usr/lib/python2.5/site-packages/FormEncode-0.7.1-py2.5.egg/formencode/declarative.py",
line 166, in singleton
setattr(cls, name, cls(declarative_count=cls.declarative_count))
TypeError: __init__() got an unexpected keyword argument 'declarative_count' |
Here is a (hopefully complete) patch against both pydoc and inspect. It |
Really don't know why this was assigned to me... |
I can't apply the patch to any current SVN version. |
The 'type' object now has the same issue: __abstractmethods__ appears in dir(type) but type.__abstractmethods__ fails with an AttributeError. |
Updated patch for 3.2. |
Updated patch that adds a test for classifying builtin types (checks that |
New changeset 902f694a7b0e by Antoine Pitrou in branch '3.2': New changeset b08bf8df8eec by Antoine Pitrou in branch 'default': |
New changeset 13f56cd8dec1 by Antoine Pitrou in branch '2.7': |
Now fixed in all 3 branches. |
Great stuff. |
This change causes the following behaviour: >>> import inspect
>>> class B(object):
... def f(self):
... pass
...
>>> inspect.getmembers(B, inspect.ismethod)
[] While I would expect the result to contain f: >>> inspect.ismethod(B.f)
True Isn't this a regression ? Regards, |
Sorry, I forgot to mention I'm using python2.7 . |
Thanks for noticing. The doc for ismethod() says: “Return true if the object is a bound method written in Python.” and the docstring agrees with that: “Return true if the object is an instance method. [...]” So the change isn't properly a regression when reading the docs. On the other hand, it's true that some code may rely on the previous behaviour, and the discrepancy between getmembers() and a manual test can be confusing. By the way, Python 3 has ismethod() right: >>> class B:
... def f(self): pass
...
>>> inspect.ismethod(B.f)
False
>>> inspect.ismethod(B().f)
True |
New changeset f824744557ba by Antoine Pitrou in branch '2.7': |
I've backed out the part of the changeset that "fixed" getmembers(), so the old behaviour is restored. Other parts of the changeset (that e.g. fixed pydoc) have not been reverted. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: