[ python-Bugs-743267 ] super passes bad arguments to __get__ when used w/class

SourceForge.net noreply at sourceforge.net
Wed Feb 25 02:06:23 EST 2004


Bugs item #743267, was opened at 2003-05-25 18:00
Message generated for change (Comment added) made by pje
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=743267&group_id=5470

Category: Type/class unification
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Phillip J. Eby (pje)
>Assigned to: Guido van Rossum (gvanrossum)
Summary: super passes bad arguments to __get__ when used w/class

Initial Comment:
Run the following code to demonstrate the issue:

====
class Getter(object):
    def __get__(self, ob, typ=None):
        print "called with", (ob, typ)

class Base(object):
    foo = Getter()

class Subclass(Base):
    pass

print
print

Base().foo
Subclass().foo
super(Subclass,Subclass()).foo

Base.foo
Subclass.foo
super(Subclass,Subclass).foo
====

Notice that super(Subclass,Subclass).foo is calling the
descriptor with the *class* object, not 'None' as is
done for the analagous cases that don't use super().

The only reason this ever "works" is because
'classmethod' ignores the 'ob' parameter to '__get__'.
 However, this breaks when using 'super' to access
property descriptors in 2.3, and it will also break any
user-defined descriptors that are accessed via super().

The behavior is the same in 2.2, and is arguably broken
there as well.  For example,
'super(someclass,someclass).X' (where 'X' is a normal
instance method) results in X being a *bound* method,
bound to the class, rather than an *unbound* method,
ready for use with an explicit instance.

Personally, I would be happy if super() grew an extra
argument to disambiguate whether you are doing a
(class,instance) or (class,class) call, anyway.  When
using super() with metaclasses, I've encountered
situations where super() guessed wrong, because I was
using a type that was both an instance of, and a
subclass of, the same type.  Being able to explicitly
request that this "class method" form of super is being
used, would eliminate this confusion as well.  In the
face of ambiguity... ;)


----------------------------------------------------------------------

>Comment By: Phillip J. Eby (pje)
Date: 2004-02-25 07:06

Message:
Logged In: YES 
user_id=56214

Assigning to Guido to request pronouncement on the correct
way to fix this before I attempt to create patch(es).

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=743267&group_id=5470



More information about the Python-bugs-list mailing list