From 3828f418e2cca6237374997f38a8477f98af1518 Mon Sep 17 00:00:00 2001 From: dylwil3 Date: Wed, 4 Feb 2026 20:37:38 -0600 Subject: [PATCH 1/4] add fixture --- crates/ruff_linter/resources/test/fixtures/refurb/FURB118.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/ruff_linter/resources/test/fixtures/refurb/FURB118.py b/crates/ruff_linter/resources/test/fixtures/refurb/FURB118.py index 9e692ba28eb92..0a6496913ef5c 100644 --- a/crates/ruff_linter/resources/test/fixtures/refurb/FURB118.py +++ b/crates/ruff_linter/resources/test/fixtures/refurb/FURB118.py @@ -163,3 +163,7 @@ def custom_decorator(func): @custom_decorator def add(x, y): return x + y + +# Regression https://github.com/astral-sh/ruff/issues/23076 +def func(rows): + rows.sort(key=lambda x: (x[x.find("=")], x[1])) From 51059926eeb34977037e122f0b8355a53b914416 Mon Sep 17 00:00:00 2001 From: dylwil3 Date: Wed, 4 Feb 2026 20:38:49 -0600 Subject: [PATCH 2/4] bad snapshot --- ...es__refurb__tests__FURB118_FURB118.py.snap | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__FURB118_FURB118.py.snap b/crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__FURB118_FURB118.py.snap index c4118d4bbac18..e4a91d6051bea 100644 --- a/crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__FURB118_FURB118.py.snap +++ b/crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__FURB118_FURB118.py.snap @@ -1009,3 +1009,27 @@ help: Replace with `operator.itemgetter(slice(-5, -3))` 133 | ) 134 | def test_inlet_asset_alias_extra_slice(self, slicer, expected): note: This is an unsafe fix and may change runtime behavior + +FURB118 [*] Use `operator.itemgetter(x.find("="), 1)` instead of defining a lambda + --> FURB118.py:169:19 + | +167 | # Regression https://github.com/astral-sh/ruff/issues/23076 +168 | def func(rows): +169 | rows.sort(key=lambda x: (x[x.find("=")], x[1])) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: Replace with `operator.itemgetter(x.find("="), 1)` +146 | +147 | # https://github.com/astral-sh/ruff/issues/19305 +148 | import pytest +149 + import operator +150 | +151 | @pytest.fixture +152 | def my_fixture_with_param(request): +-------------------------------------------------------------------------------- +167 | +168 | # Regression https://github.com/astral-sh/ruff/issues/23076 +169 | def func(rows): + - rows.sort(key=lambda x: (x[x.find("=")], x[1])) +170 + rows.sort(key=operator.itemgetter(x.find("="), 1)) +note: This is an unsafe fix and may change runtime behavior From 5bb1d6d43d910b4d2be943ac2499d2854210fe04 Mon Sep 17 00:00:00 2001 From: dylwil3 Date: Wed, 4 Feb 2026 20:39:28 -0600 Subject: [PATCH 3/4] check that argument subscripts do not involve arg in tuple --- .../src/rules/refurb/rules/reimplemented_operator.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/ruff_linter/src/rules/refurb/rules/reimplemented_operator.rs b/crates/ruff_linter/src/rules/refurb/rules/reimplemented_operator.rs index 963a09449838c..059b3d366aa0c 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/reimplemented_operator.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/reimplemented_operator.rs @@ -311,7 +311,12 @@ fn itemgetter_op_tuple( .iter() .map(|expr| { expr.as_subscript_expr() - .filter(|expr| is_same_expression(arg, &expr.value)) + .filter(|expr| { + is_same_expression(arg, &expr.value) + && !any_over_expr(expr.slice.as_ref(), &|expr| { + is_same_expression(arg, expr) + }) + }) .map(|expr| expr.slice.as_ref()) .map(|slice| subscript_slice_to_string(slice, locator).to_string()) }) From abade8c09e00f51fd45b7fa1f550ff075dd0cf65 Mon Sep 17 00:00:00 2001 From: dylwil3 Date: Wed, 4 Feb 2026 20:40:07 -0600 Subject: [PATCH 4/4] good snapshot --- ...es__refurb__tests__FURB118_FURB118.py.snap | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__FURB118_FURB118.py.snap b/crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__FURB118_FURB118.py.snap index e4a91d6051bea..c4118d4bbac18 100644 --- a/crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__FURB118_FURB118.py.snap +++ b/crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__FURB118_FURB118.py.snap @@ -1009,27 +1009,3 @@ help: Replace with `operator.itemgetter(slice(-5, -3))` 133 | ) 134 | def test_inlet_asset_alias_extra_slice(self, slicer, expected): note: This is an unsafe fix and may change runtime behavior - -FURB118 [*] Use `operator.itemgetter(x.find("="), 1)` instead of defining a lambda - --> FURB118.py:169:19 - | -167 | # Regression https://github.com/astral-sh/ruff/issues/23076 -168 | def func(rows): -169 | rows.sort(key=lambda x: (x[x.find("=")], x[1])) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: Replace with `operator.itemgetter(x.find("="), 1)` -146 | -147 | # https://github.com/astral-sh/ruff/issues/19305 -148 | import pytest -149 + import operator -150 | -151 | @pytest.fixture -152 | def my_fixture_with_param(request): --------------------------------------------------------------------------------- -167 | -168 | # Regression https://github.com/astral-sh/ruff/issues/23076 -169 | def func(rows): - - rows.sort(key=lambda x: (x[x.find("=")], x[1])) -170 + rows.sort(key=operator.itemgetter(x.find("="), 1)) -note: This is an unsafe fix and may change runtime behavior