Disable E741 in stub files#13119
Merged
AlexWaygood merged 3 commits intoastral-sh:mainfrom Aug 27, 2024
Merged
Conversation
Contributor
|
AlexWaygood
approved these changes
Aug 27, 2024
Member
AlexWaygood
left a comment
There was a problem hiding this comment.
Thanks @calumy, this is great! I pushed a few small fixups to your PR:
- I made the change preview-only for now; we can stabilise it in Ruff 0.7. Strictly speaking we could probably get away with doing this in a patch release, since it's a reduction in scope rather than an increase in scope -- but it's still a big change in scope, so I feel much safer doing it in preview only first :-)
- I added some docs on how it works differently for
.pyifiles - I made it a bit more DRY by putting the check for whether it's a stub file in the
ambiguous_variable_name()function itself, so we don't have to repeat it everywhere.
LMK if you'd like me to explain any of it, very happy to do so :-)
Contributor
Author
All makes sense to me; thanks for laying it out clearly. |
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
As noted in #10569, E741 should not be active in
.pyifiles as the file author does not control the variable name. Instead, this is deferred to the author of the package for which the stub file is substituting for.My rust skills are being stretched here. I assume there is a more elegant way of implementing the check
checker.source_type != PySourceType::Stubin theambiguous_variable_namefunction so that it is only implemented in one place (similar tonon_unique_enums); however, I can't get the borrow checker to agree to this.Test Plan
Added a new test case were
E741.pywas duplicated and renamed toE741.pyiand a snapshot to confirm that no errors were raised for this new case as E741 should be disabled in.pyifiles.