-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
FURB110 may break code #11398
Comments
Could you provide a minimal code snippet to try? |
I'm able to reproduce it using the following example. ❯ bat test.py
───────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ File: test.py
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ location_place_id = "abc"
2 │ city_id = None
3 │ place_id = (
4 │ location_place_id
5 │ if location_place_id
6 │ else "ghi"
7 │ if city_id
8 │ else None
9 │ )
10 │
11 │ print(place_id)
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
❯ python test.py
abc
After running ❯ ruff check test.py --preview --select FURB110 --fix
Found 1 error (1 fixed, 0 remaining).
❯ bat test.py
───────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ File: test.py
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ location_place_id = "abc"
2 │ city_id = None
3 │ place_id = (
4 │ location_place_id or "ghi"
5 │ if city_id
6 │ else None
7 │ )
8 │
9 │ print(place_id)
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
❯ python test.py
None The correct fix here should wrap the second ❯ bat test.py
───────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ File: test.py
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ location_place_id = "abc"
2 │ city_id = None
3 │ place_id = location_place_id or ("ghi" if city_id else None)
4 │ print(place_id)
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
❯ python test.py
abc |
Thanks @blueraft , and yes that is exactly the fix I did ;) |
Probably a precedence issue. |
I think the edit content should be generated using the ruff/crates/ruff_linter/src/rules/refurb/rules/if_exp_instead_of_or_operator.rs Lines 85 to 92 in 1c18408
|
Raw strings are better right now IMO since they preserve more of the verbatim content. I think I'd rather augment the fix to parenthesize if needed. |
ruff --preview --select FURB110 --fix
FURB110 autofix (with preview) changed code
into
With inputs
location_place_id = "abc"
andcity_id = None
, the code previously returned "abc" but now returns NoneThe text was updated successfully, but these errors were encountered: