[Fix error]: Ruff UP007 fix introduces syntax error with nested string type annotations #14132
Labels
bug
Something isn't working
great writeup
A wonderful example of a quality contribution
help wanted
Contributions especially welcome
When running Ruff's auto-fix for UP007 (non-pep604-annotation), it introduces a syntax error when handling nested quotes in type annotations. The specific case occurs when using string literals for forward references that contain quotes within quotes.
Minimal Reproducible Example
Current Behavior
Running
ruff check . --fix
produces:The code itself is valid Python and works correctly with type checkers. The nested quote structure (
'AClass'
inside"tuple[...]"
) is a legitimate pattern for forward references in type annotations, even tough the quotes are redundant.Expected Behavior
Ruff should either:
Environment
ruff check . --fix
Configuration
Additional Context
This appears to be an edge case in quote handling for type annotations. While the syntax may look unusual, it's valid Python and is correctly interpreted by type checkers. The UP007 fixer might need to be more careful when handling nested quotes in type annotation strings.
The text was updated successfully, but these errors were encountered: