ruff/crates/ruff_linter/resources/test/fixtures/refurb
Dan Parizher 291699b375
[`refurb`] `FURB164` fix should validate arguments and should usually be marked unsafe (#19136)
## Summary

Fixes #19076

An attempt at fixing #19076 where the rule could change program behavior
by incorrectly converting from_float/from_decimal method calls to
constructor calls.

The fix implements argument validation using Ruff's existing type
inference system (`ResolvedPythonType`, `typing::is_int`,
`typing::is_float`) to determine when conversions are actually safe,
adds logic to detect invalid method calls (wrong argument counts,
incorrect keyword names) and suppress fixes for them, and changes the
default fix applicability from `Safe` to `Unsafe` with safe fixes only
offered when the argument type is known to be compatible and no
problematic keywords are used.

One uncertainty is whether the type inference catches all possible edge
cases in complex codebases, but the new approach is significantly more
conservative and safer than the previous implementation.

## Test Plan

I updated the existing test fixtures with edge cases from the issue and
manually verified behavior with temporary test files for
valid/unsafe/invalid scenarios.

---------

Co-authored-by: Brent Westbrook <brentrwestbrook@gmail.com>
2025-07-16 15:38:33 +00:00
..
FURB101.py [`refurb`] Do not allow any keyword arguments for `read-whole-file` in `rb` mode (`FURB101`) (#10803) 2024-04-06 12:41:39 -04:00
FURB103.py Improve handling of builtin symbols in linter rules (#10919) 2024-04-16 11:37:31 +01:00
FURB105.py Treat `sep` arguments with effects as unsafe removals (#13165) 2024-08-30 12:17:47 -04:00
FURB110.py Respect operator precedence in `FURB110` (#11464) 2024-05-19 03:17:11 +00:00
FURB113.py Avoid `FURB113` autofix if comments are present (#8494) 2023-11-09 03:10:11 +00:00
FURB116.py [`refurb`] Mark autofix as safe only for number literals in `FURB116` (#17692) 2025-05-12 16:08:12 -04:00
FURB118.py Fix bug where methods defined using lambdas were flagged by FURB118 (#14639) 2024-11-28 12:58:23 +00:00
FURB122.py [`refurb`] Parenthesize lambda and ternary expressions in iter (`FURB122`, `FURB142`) (#18592) 2025-06-09 16:07:34 -04:00
FURB129.py [`refurb`] Mark `FURB129` autofix as unsafe if there's comments in the `readlines` call (#18858) 2025-06-22 08:51:37 +01:00
FURB131.py Improve inference capabilities of the `BuiltinTypeChecker` (#10976) 2024-04-16 18:53:22 +01:00
FURB132.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
FURB136.py Implement FURB136 (#8664) 2023-11-15 18:10:13 +00:00
FURB140.py Avoid suggesting starmap when arguments are used outside call (#11830) 2024-06-10 17:10:06 -04:00
FURB142.py [`refurb`] Parenthesize lambda and ternary expressions in iter (`FURB122`, `FURB142`) (#18592) 2025-06-09 16:07:34 -04:00
FURB145.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
FURB148.py Check sequence type before triggering `unnecessary-enumerate` (`FURB148`) `len` suggestion (#7781) 2023-10-03 14:39:14 +00:00
FURB152.py [`refurb`] Avoid false positives for `math-constant` (`FURB152`) (#9290) 2023-12-27 09:45:37 -05:00
FURB154.py [`refurb`] Implement `repeated-global` (`FURB154`) (#11187) 2024-06-08 20:35:40 +00:00
FURB156.py [FURB156] Do not consider docstring(s) (#16391) 2025-02-26 16:30:13 +00:00
FURB157.py [`refurb`] Avoid panicking `unwrap` in `verbose-decimal-constructor` (`FURB157`) (#16777) 2025-03-17 05:09:07 -05:00
FURB161.py [`refurb`] Mark the `FURB161` fix unsafe except for integers and booleans (#17240) 2025-04-18 13:46:01 -04:00
FURB162.py [`refurb`] Manual timezone monkeypatching (`FURB162`) (#16113) 2025-02-18 14:35:33 +01:00
FURB163.py [`refurb`] Fix `FURB163` autofix creating a syntax error for `yield` expressions (#18756) 2025-06-23 10:13:03 +02:00
FURB164.py [`refurb`] `FURB164` fix should validate arguments and should usually be marked unsafe (#19136) 2025-07-16 15:38:33 +00:00
FURB166.py [`refurb`] Implement `int-on-sliced-str` (`FURB166`) (#10650) 2024-04-02 19:29:42 +00:00
FURB167.py [`refurb`] Implement `regex-flag-alias` with fix (`FURB167`) (#9516) 2024-01-14 23:40:17 +00:00
FURB168.py [`refurb`] Fix false positive on empty tuples (`FURB168`) (#19058) 2025-07-01 10:26:41 -04:00
FURB169.py [`refurb`] Also report non-name expressions (`FURB169`) (#15905) 2025-02-05 08:46:37 +01:00
FURB171_0.py [`refurb`] Add coverage of `set` and `frozenset` calls (`FURB171`) (#18035) 2025-05-29 14:59:49 -04:00
FURB171_1.py [`refurb`] Add coverage of `set` and `frozenset` calls (`FURB171`) (#18035) 2025-05-29 14:59:49 -04:00
FURB177.py [`refurb`] Implement `implicit-cwd` (FURB177) (#7704) 2023-09-29 02:18:59 +00:00
FURB180.py [`refurb`] Implement `metaclass_abcmeta` (`FURB180`) (#9658) 2024-01-31 22:31:12 +00:00
FURB181.py [`refurb`] Implement `hashlib-digest-hex` (`FURB181`) (#9077) 2023-12-10 02:00:11 +00:00
FURB187.py [`refurb`] Implement `list_assign_reversed` lint (FURB187) (#10212) 2024-03-21 17:09:09 +00:00
FURB188.py [`refurb`] Correctly handle lengths of literal strings in `slice-to-remove-prefix-or-suffix` (`FURB188`) (#16237) 2025-02-18 12:52:26 -06:00
FURB189.py [refurb] Check for subclasses includes subscript expressions (FURB189) (#16155) 2025-02-14 20:21:26 +01:00
FURB192.py [`refurb`] New rule to suggest min/max over sorted() (`FURB192`) (#10868) 2024-04-23 01:13:57 +00:00