a patch to inspect and a non-feature request

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

On 5/12/05, Michele Simionato <michele.simionato@gmail.com> wrote:
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.
+1 while super doesn't work with "meta-attributes" and classmethods: py> class B(object): ... "The B type" ... @classmethod ... def m(cls): ... print "B.m" ... py> class C(B): ... @classmethod ... def m(cls): ... print "C.m" ... cls._sup.m() ... py> C._sup = super(C) py> super(C, C).__doc__ 'The B type' py> super(C, C).__name__ Traceback (most recent call last): File "<interactive input>", line 1, in ? AttributeError: 'super' object has no attribute '__name__' py> C().m() C.m Traceback (most recent call last): File "<interactive input>", line 1, in ? File "<interactive input>", line 5, in m AttributeError: 'super' object has no attribute 'm' STeVe -- You can wordify anything if you just verb it. --- Bucky Katt, Get Fuzzy

On 5/12/05, Steven Bethard <steven.bethard@gmail.com> wrote:
super doesn't work with "meta-attributes" and classmethods:
py> super(C, C).__name__ Traceback (most recent call last): File "<interactive input>", line 1, in ? AttributeError: 'super' object has no attribute '__name__'
Actually this is the Right Thing to do for super. It is something to be aware of, not something to change. Since __name__ is a descriptor defined in the type metaclass and not an attribute defined in the base class, super correctly does not retrieve it. It is enough to add some documentation about "super" caveats and nonobvious points. What I really dislike is super called with only one argument since it has many unpleasant surprises and not real advantages :-( Michele Simionato
participants (2)
-
Michele Simionato
-
Steven Bethard