Is it time to deprecate unbound super methods?

As long ago as Python 3.0, there was talk about deprecating
unbound super objects
, which aren’t documented very well, and are often confusing. Many people assume that if bound super objects dispatch to bound methods:

super(T, obj).method  # returns method bound to obj

then obviously unbound super objects must dispatch to unbound methods:

super(T).method  # returns unbound method

(I know that’s what I assumed) but that’s not the case.

Michele Simionato suggested that (1) there’s only a single use-case for unbound super objects, and (2) they don’t even work correctly for that use-case.

Now that we have the zero-argument form of super(), does that remove the motivation for unbound super objects? Should they be deprecated in 3.9 for removal in 3.10?

Or keep them and document them better?

For those that wonder about what the single-argument version does: it creates an unbound super() instance, you bind that instance, then look up attributes. E.g. store super(Type) on the class then look that up on the instance. See my answer on a Stack Overflow question.

The idea was that you’d be able to avoid repeating the class all the time:

class Foo(Bar):
    def override(self):
        return "spam" + self.__sup.override()

# set manually or have a metaclass or __init_subclass__ take care of this attribute
Foo._Foo__sup = super(Foo)

And the case were that doesn’t work is classmethods, because cls.__sup won’t be bound.

With super() now picking up the class from a closure the primary use case is gone, I wouldn’t expect anyone to be using the single-argument version.

1 Like

I didn’t even know the single-argument version existed. The only two forms I’ve ever used are super(Type, self) and super().

1 Like

Yeah, let’s start deprecating this.

1 Like