Bug description
bad-super-call looks at every super(X, y) call in a method, including those inside functions nested in the method, and compares X with the class of the enclosing method. When the nested function is itself going to become a method of some other class (it takes its own self/cls and is attached later), X is legitimately a different class and the message is a false positive.
The stdlib does this in Lib/_py_warnings.py (warnings.deprecated.__call__):
class deprecated:
def __call__(self, arg):
if isinstance(arg, type):
def __init_subclass__(cls, *args, **kwargs):
warn(...)
return super(arg, cls).__init_subclass__(*args, **kwargs)
arg.__init_subclass__ = classmethod(__init_subclass__)
return arg
Pylint reports E1003: Bad first argument 'arg' given to super() (bad-super-call) on the super(arg, cls) line, although arg is exactly the class that __init_subclass__ is being attached to and cls is the nested function's own first parameter, not self of __call__.
Configuration
No response
Command used
pylint --disable=all --enable=bad-super-call a.py
Pylint output
************* Module a
a.py:9:23: E1003: Bad first argument 'arg' given to super() (bad-super-call)
Expected behavior
No message. When the second argument of super() is a parameter of the nested function rather than of the method being checked, the call does not refer to the enclosing class and the check should skip it. (A nested helper that still passes the method's own self, e.g. super(Other, self).m(), should keep being reported.)
Pylint version
pylint 4.1.0-dev0
astroid 4.4.0-dev0
Python 3.13.11
OS / Environment
macOS
Additional dependencies
No response
Bug description
bad-super-calllooks at everysuper(X, y)call in a method, including those inside functions nested in the method, and comparesXwith the class of the enclosing method. When the nested function is itself going to become a method of some other class (it takes its ownself/clsand is attached later),Xis legitimately a different class and the message is a false positive.The stdlib does this in
Lib/_py_warnings.py(warnings.deprecated.__call__):Pylint reports
E1003: Bad first argument 'arg' given to super() (bad-super-call)on thesuper(arg, cls)line, althoughargis exactly the class that__init_subclass__is being attached to andclsis the nested function's own first parameter, notselfof__call__.Configuration
No response
Command used
Pylint output
Expected behavior
No message. When the second argument of
super()is a parameter of the nested function rather than of the method being checked, the call does not refer to the enclosing class and the check should skip it. (A nested helper that still passes the method's ownself, e.g.super(Other, self).m(), should keep being reported.)Pylint version
OS / Environment
macOS
Additional dependencies
No response