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
Open
Fix false positive bad-super-call in a nested function that acts as a method of another class#11314ekanshul wants to merge 1 commit into
bad-super-call in a nested function that acts as a method of another class#11314ekanshul wants to merge 1 commit into
Conversation
…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 Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #11314 +/- ##
=======================================
Coverage 96.41% 96.41%
=======================================
Files 178 178
Lines 20078 20083 +5
=======================================
+ Hits 19358 19363 +5
Misses 720 720
🚀 New features to boost your workflow:
|
Contributor
|
🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉 This comment was generated for commit 8bf2bd7 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of Changes
Description
bad-super-callcompares the first argument of everysuper()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 inwarnings.deprecated.__call__in the stdlib (Lib/_py_warnings.py):Here
super(arg, cls)is correct, yet pylint reportedBad 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 (clsabove). A nested helper that still passes the method's ownself, such assuper(Other, self).m(), is still reported; the functional test covers both cases.Closes #11313