[refurb] Mark the FURB161 fix unsafe except for integers and booleans#17240
[refurb] Mark the FURB161 fix unsafe except for integers and booleans#17240ntBre merged 7 commits intoastral-sh:mainfrom
refurb] Mark the FURB161 fix unsafe except for integers and booleans#17240Conversation
|
|
This PR doesn’t fully fix #16457. The point of that issue is that FURB161 should be unsafe by default, with a few exceptions. This PR keeps it safe by default, the only exception being string literals. |
Thanks for the explanation. I approved the modification to make the rule unsafe if we can not determine if the argument of the |
|
Using |
ntBre
left a comment
There was a problem hiding this comment.
Thanks for working on this! Overall I think this is good, but we can simplify things a bit by using a fix Applicability, and then I think we can do a better job with type inference with ResolvedPythonType::from, specifically for Expr::BinOp (cases like 1 + 2) and for Expr::UnOp (cases like -1).
If we extend the safe handling to bool, we may also be able to resolve expressions like True or False.
...linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__FURB161_FURB161.py.snap
Show resolved
Hide resolved
...linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__FURB161_FURB161.py.snap
Outdated
Show resolved
Hide resolved
Co-authored-by: Brent Westbrook <36778786+ntBre@users.noreply.github.com>
Hey @ntBre |
|
Thanks, it looks good to me! Let's save this for a follow-up PR like the ruff/crates/ruff_python_semantic/src/analyze/typing.rs Lines 968 to 971 in 27a315b You definitely don't have to work on this, just a couple of ideas if you're interested :) I pushed two tiny tweaks:
I'll merge as soon as CI passes! |
refurb] Unsafe fixes in FURB161refurb] Mark the FURB161 fix unsafe except for integers and booleans
The PR fixes #16457 .
Specifically,
FURB161is marked safe, but the rule generates safe fixes only in specific cases. Therefore, we attempt to mark the fix as unsafe when we are not in one of these cases.For instances, the fix is marked as aunsafe just in case of strings (as pointed out in the issue). Let me know if I should change something.