[Python-Dev] a patch to inspect and a non-feature request
Michele Simionato
michele.simionato at gmail.com
Thu May 12 13:23:11 CEST 2005
Well, I logged into Sourceforge with the idea of filing my feature request
about copying functions, and then my eye went on my previous submissions.
It seems it takes some time to fix non-critical bugs, isn't it? ;)
Two years ago, I discovered a bug with pydoc for classes containing "super"
objects:
>>> class C(object):
... pass
>>> C.s = super(C)
>>> help(C) # aargh!!
I filed that bug 25 months ago and it is still there (actually Brett
Cannot fixed it but then somebody else broke his patch).
Clearly nobody uses this feature and the bug fixing is not at
all urgent still it disturbs me, so I have worked out
a patch. Actually, the problem is not in pydoc but in inspect,
that treats super objects as methods, whereas they should be treated
as data. Here is the patch:
$ diff -c /home/micheles/python/dist/src/Lib/inspect.py inspect.py
*** /home/micheles/python/dist/src/Lib/inspect.py Thu May 12 13:05:10 2005
--- inspect.py Thu May 12 13:06:55 2005
***************
*** 77,83 ****
and not hasattr(object, "__set__") # else it's a data descriptor
and not ismethod(object) # mutual exclusion
and not isfunction(object)
! and not isclass(object))
def isdatadescriptor(object):
"""Return true if the object is a data descriptor.
--- 77,84 ----
and not hasattr(object, "__set__") # else it's a data descriptor
and not ismethod(object) # mutual exclusion
and not isfunction(object)
! and not isclass(object)
! and not isinstance(object, super))
def isdatadescriptor(object):
"""Return true if the object is a data descriptor.
It changes the code of ismethoddescriptor to make sure that super objects
are not treated as methods.
BTW, I have downloaded the CVS version of Python and run test_inspect
against the patch and it is working. However, introspection tools have
the tendency to be very fragile (especially with the rate of changes
in Python) and it is possible that this fix would break something else.
Let The Powers That Be to decide.
The test suite should be augmented with a test such
>>> inspect.ismethoddescriptor(C.s)
False
In my experience super is a huge can of worms and actually I have a non-feature
request about the descriptor aspect of super: I would like super's
__get__ method
and the possibily to call super with just one argument to be removed
in Python 3000.
They are pretty much useless (yes I know of "autosuper") and error prone.
Michele Simionato
More information about the Python-Dev
mailing list