Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly handle references in __all__ definitions when renaming symbols in autofixes #10527

Merged
merged 8 commits into from Mar 22, 2024

Conversation

AlexWaygood
Copy link
Member

Summary

This PR is stacked on top of #10525 -- review that one first!

This PR changes the logic in ruff_linter/src/renamer.rs to correctly rename references to symbols if those references are string references inside __all__ definitions. In order for the renamer to be able to distinguish between __all__ references (which need to have their quotes stripped before they can be renamed) and other references, a new flag is added to the SemanticModelFlags bitflag, DUNDER_ALL_DEFINITION. This flag is inserted into the semantic model when the model is visiting the r.h.s. of an __all__ definition.

Fixes #10508

Test Plan

Several new test cases have been added for PYI025. These include __all__ definitions with triple-quoted strings, raw strings and implicitly concatenated strings.

@AlexWaygood AlexWaygood added bug Something isn't working fixes Related to suggested fixes for violations linter Related to the linter labels Mar 22, 2024
Copy link
Contributor

github-actions bot commented Mar 22, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Base automatically changed from dunder-all-ranges to main March 22, 2024 18:38
Copy link
Member

@charliermarsh charliermarsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@AlexWaygood AlexWaygood merged commit 9feb9b0 into main Mar 22, 2024
17 checks passed
@AlexWaygood AlexWaygood deleted the pyi025-incorrect-fix branch March 22, 2024 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixes Related to suggested fixes for violations linter Related to the linter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Strange autofix for PYI025 if "Set" is included in __all__
2 participants