-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parenthesize expressions prior to LibCST parsing (#6742)
<!-- Thank you for contributing to Ruff! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary This PR adds a utility for transforming expressions via LibCST that automatically wraps the expression in parentheses, applies a user-provided transformation, then strips the parentheses from the generated code. LibCST can't parse arbitrary expression ranges, since some expressions may require parenthesization in order to be parsed properly. For example: ```python option = ( '{name}={value}' .format(nam=name, value=value) ) ``` In this case, the expression range is: ```python '{name}={value}' .format(nam=name, value=value) ``` Which isn't valid on its own. So, instead, we add "fake" parentheses around the expression. We were already doing this in a few places, so this is mostly formalizing and DRYing up that pattern. Closes #6720.
- Loading branch information
1 parent
5c1f7fd
commit 214eb70
Showing
12 changed files
with
317 additions
and
279 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.