1. Joe Amenta
  2. lib3to2
  3. Issues
Issue #19 resolved

super() with no arguments is not refactored.

Joe Amenta
repo owner created an issue

In python3, one can call super() with no arguments, and the stack frame is searched for class and the first argument. In python2, that call must be explicit.

3to2 does not do this.

Comments (9)

  1. Łukasz Langa
    • changed status to new
    • marked as bug

    The way you're fixing it is unfortunately wrong. Take this example:

    class Base(object):
        def meow(self):
            return "Meow"
    class Parent(Base):
        def meow(self):
            supercall = super().meow()
            return "'{}' - said the cat.".format(supercall)
    class Child(Parent):

    As you can see the super(self.__class__, self) won't work here and the code will raise

    RuntimeError: maximum recursion depth exceeded while calling a Python object

  2. Éric Araujo
    • changed status to new

    In a foo method defined in a Parent class the super call needs to have Parent as second argument, because self.class can be a subclass. This bug is present in the existing super fixer.

  3. Anonymous

    I've altered fix_super.py to handle the more complex inheritance case that gives a recursion error.

    The changed version will try to use the name of the class if it can parse it out, instead of self.class. This means that given:

    class C:
        def m(self):

    it will generate

    class C:
        def m(self):
            super(C, self)

    The diff is available from:


    An example of valid Python 3 that provokes the behaviour is given here:


    An example of the Python 2 broken behaviour as generated by 3to2 (rev 3d4fe20d5360) is here:


    Finally, an example of the Python 2 fixed behaviour as generated by 3to2 (rev 3d4fe20d5360 & the attached diff) is here:


  4. Log in to comment