Skip to content
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

PLR1716 fix introduces a syntax error with unbalanced parentheses #13524

Closed
dscorbett opened this issue Sep 26, 2024 · 3 comments · Fixed by #14781
Closed

PLR1716 fix introduces a syntax error with unbalanced parentheses #13524

dscorbett opened this issue Sep 26, 2024 · 3 comments · Fixed by #14781
Assignees
Labels
bug Something isn't working fixes Related to suggested fixes for violations

Comments

@dscorbett
Copy link

When the two expressions to be collapsed by boolean-chained-comparison (PLR1716) are parenthesized with different numbers of parentheses, the fix makes Ruff fail.

$ ruff --version
ruff 0.6.8
$ echo '(a < b) and b < c' | ruff check --isolated --preview --select PLR1716 - --fix

error: Fix introduced a syntax error. Reverting all changes.

This indicates a bug in Ruff. If you could open an issue at:

    https://github.com/astral-sh/ruff/issues/new?title=%5BFix%20error%5D

...quoting the contents of `-`, the rule codes PLR1716, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!

(a < b) and b < c
-:1:2: PLR1716 Contains chained boolean comparison that can be simplified
  |
1 | (a < b) and b < c
  |  ^^^^^^^^^^^^^^^^ PLR1716
  |
  = help: Use a single compare expression

Found 1 error.
[*] 1 fixable with the `--fix` option.
@AlexWaygood AlexWaygood added bug Something isn't working fixes Related to suggested fixes for violations labels Sep 26, 2024
@zanieb zanieb self-assigned this Sep 26, 2024
@zanieb
Copy link
Member

zanieb commented Sep 26, 2024

Ah this looks like.. hard to fix. We can at least not offer an invalid fix here.

zanieb added a commit that referenced this issue Sep 26, 2024
…parenthesis (#13527)

Related to #13524

Doesn't offer a valid fix, opting to instead just not offer a fix at
all. If someone points me to a good way to handle parenthesis here I'm
down to try to fix the fix separately, but it looks quite hard.
@dscorbett
Copy link
Author

This was addressed in version 0.6.9. Is there anything left to do for this issue?

@zanieb
Copy link
Member

zanieb commented Oct 4, 2024

We don't offer the fix, but we can do better and offer the fix with proper handling.

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
4 participants