Skip to content

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

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

Open
dscorbett opened this issue Apr 1, 2025 · 0 comments · May be fixed by #17220
Open

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

dscorbett opened this issue Apr 1, 2025 · 0 comments · May be fixed by #17220
Labels
bug Something isn't working fixes Related to suggested fixes for violations

Comments

@dscorbett
Copy link

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)

@MichaReiser MichaReiser added the bug Something isn't working label Apr 1, 2025
@AlexWaygood AlexWaygood added the fixes Related to suggested fixes for violations label Apr 1, 2025
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
Projects
None yet
3 participants