Skip to content

Fix false positive bad-super-call in a nested function that acts as a method of another class - #11314

Open
ekanshul wants to merge 1 commit into
pylint-dev:mainfrom
ekanshul:fix-bad-super-call-nested-method
Open

Fix false positive bad-super-call in a nested function that acts as a method of another class#11314
ekanshul wants to merge 1 commit into
pylint-dev:mainfrom
ekanshul:fix-bad-super-call-nested-method

Conversation

@ekanshul

Copy link
Copy Markdown
Contributor

Type of Changes

Type
🐛 Bug fix
✨ New feature
🔨 Refactoring
📜 Docs

Description

bad-super-call compares the first argument of every super() call found in a method, including calls inside functions nested in that method, with the enclosing class. A nested function can itself become a method of another class, as in warnings.deprecated.__call__ in the stdlib (Lib/_py_warnings.py):

def __call__(self, arg):
    def __init_subclass__(cls, *args, **kwargs):
        return super(arg, cls).__init_subclass__(*args, **kwargs)
    arg.__init_subclass__ = classmethod(__init_subclass__)

Here super(arg, cls) is correct, yet pylint reported Bad first argument 'arg' given to super().

The check now skips a super() call inside a nested function when its second argument is one of that nested function's own parameters (cls above). A nested helper that still passes the method's own self, such as super(Other, self).m(), is still reported; the functional test covers both cases.

Closes #11313

…thod

``bad-super-call`` compared the first argument of every ``super()`` call
found in a method, including calls inside functions nested in that method,
with the enclosing class. A nested function can itself become a method of
another class (for example ``arg.__init_subclass__ = classmethod(func)`` in
``warnings.deprecated``), in which case ``super(arg, cls)`` is correct.
Skip the check when the second argument of ``super()`` is one of the nested
function's own parameters.

Closes pylint-dev#11313

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.41%. Comparing base (f8ea10a) to head (8bf2bd7).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #11314   +/-   ##
=======================================
  Coverage   96.41%   96.41%           
=======================================
  Files         178      178           
  Lines       20078    20083    +5     
=======================================
+ Hits        19358    19363    +5     
  Misses        720      720           
Files with missing lines Coverage Δ
pylint/checkers/newstyle.py 96.42% <100.00%> (+0.35%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉

This comment was generated for commit 8bf2bd7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False positive bad-super-call for a nested function that becomes a method of another class

1 participant