Skip to content

UP018 fix introduces a syntax error when the argument contains a newline #17124

@dscorbett

Description

@dscorbett

Summary

The fix for native-literals (UP018) can introduce a syntax error when the argument contains a newline between a unary + or - and a number literal. It should wrap the expression with parentheses as needed to avoid the error.

$ cat >up018.py <<'# EOF'
int(-
1)
# EOF

$ ruff --isolated check up018.py --select UP018 --diff 2>&1 | grep error:
error: Fix introduced a syntax error. Reverting all changes.

Version

ruff 0.11.2 (4773878 2025-03-21)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixesRelated to suggested fixes for violations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions