mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:37 +00:00
![]() <!-- 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 https://github.com/astral-sh/ruff/issues/6720. |
||
---|---|---|
.. | ||
flake8_to_ruff | ||
ruff | ||
ruff_benchmark | ||
ruff_cache | ||
ruff_cli | ||
ruff_dev | ||
ruff_diagnostics | ||
ruff_formatter | ||
ruff_index | ||
ruff_macros | ||
ruff_python_ast | ||
ruff_python_codegen | ||
ruff_python_formatter | ||
ruff_python_index | ||
ruff_python_literal | ||
ruff_python_parser | ||
ruff_python_resolver | ||
ruff_python_semantic | ||
ruff_python_stdlib | ||
ruff_python_trivia | ||
ruff_shrinking | ||
ruff_source_file | ||
ruff_text_size | ||
ruff_wasm |