[flake8-self] Recognize Self-typed expressions in SLF001#24148
Closed
chinar-amrutkar wants to merge 1 commit intoastral-sh:mainfrom
Closed
[flake8-self] Recognize Self-typed expressions in SLF001#24148chinar-amrutkar wants to merge 1 commit intoastral-sh:mainfrom
Self-typed expressions in SLF001#24148chinar-amrutkar wants to merge 1 commit intoastral-sh:mainfrom
Conversation
Variables annotated with (from or ) are now recognized as same-class instances and no longer trigger SLF001 for private member access. Fixes astral-sh#24140
Member
|
Thank you. There's already a PR for the very same issue, see #24144 I'll close this one but if you have time, would you mind taking a look at the other PR to see if there's something missing |
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.
Summary
Fixes #24140
Variables annotated with
Self(fromtypingortyping_extensions) are now recognized as same-class instances and no longer trigger SLF001 for private member access.Changes
Added Self type check in SameClassInstanceChecker::match_annotation using semantic.match_typing_expr(annotation, "Self")
Added test fixture SLF001_self.py covering: Self annotation on variable, Self annotation on parameter, Self in classmethod, and cross-class access (still flagged)
Test Plan
this: Self = self accessing this._private -> no diagnostic
other: Self as parameter accessing other._private -> no diagnostic
other: DifferentClass accessing other._private -> SLF001 still flagged