PY-CLAS0010 · dynamic_super_receiver
Count super calls whose first argument is computed from the receiver.
This is a deterministic rule for python. Read its implementation.
Definition
Section titled “Definition”Report a method that calls a member on super(type(self), self) or on super(self.__class__, self). Both spellings look like a way to avoid repeating the class name and both recurse
forever the moment somebody subclasses the type, because the first argument is resolved at run
time to the object’s actual class, so the lookup restarts one step below where it started and
reaches the same method again. The value is the number of such calls.
Writing super() states the enclosing class at compile time and cannot make that mistake,
which is why it is the only spelling worth having in a body that has one.
Evidence
Section titled “Evidence”The finding names the method and counts the calls inside it. A super object merely assigned
to a name is not counted, since the defect is the lookup rather than the construction. The
value is the number of super calls whose first argument is computed from the receiver.
Exceptions
Section titled “Exceptions”A first argument stating a class outright is left alone, even when it names an ancestor rather than the enclosing class, because skipping a step through the resolution order on purpose is a legal thing to do and telling it from an unrelated class needs the ancestors of the class beside the source of its methods, which no single fact carries.
Examples
Section titled “Examples”class Engine(Base): def run(self): return super(type(self), self).run()class Engine(Base): def run(self): return super().run()References
Section titled “References”- Generalizes Pylint E1003 bad-super-call. Open reference
- Cites “The Python Standard Library”,
superand the zero-argument form. Open reference - Cites “Python’s super() Considered Super”. Open reference