Skip to content

Commit c2f4b25

Browse files
worksbyfridayclaude
andcommitted
Add coverage for compound expression branches in _is_simple_expr
- Add test cases for MemberExpr (c.y), UnaryExpr (-1), and OpExpr (a + b) as non-common operands that are simple and should still trigger FURB108 - Add pragma: no cover for unreachable fallback returns (matches existing pattern in common.py) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b07398b commit c2f4b25

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

refurb/checks/logical/use_in.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def _is_simple_expr(node: Expression) -> bool:
7878
case IndexExpr() | CallExpr():
7979
return False
8080

81-
return False
81+
return False # pragma: no cover
8282

8383

8484
def _get_non_common_operands(node: OpExpr) -> list[Expression] | None:
@@ -97,7 +97,7 @@ def _get_non_common_operands(node: OpExpr) -> list[Expression] | None:
9797
operands = [a, b, c, d]
9898
return [op for i, op in enumerate(operands) if i not in indices]
9999

100-
return None
100+
return None # pragma: no cover
101101

102102

103103
def create_message(indices: tuple[int, int]) -> str:

test/data/err_108.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ class C:
2222
_ = "abc" == x or "def" == x
2323
_ = "abc" == x or x == "def"
2424

25+
# simple compound expressions should still match
26+
_ = x == c.y or x == "def"
27+
_ = x == -1 or x == 1
28+
a = 1
29+
b = 2
30+
_ = x == a + b or x == "def"
31+
2532
# these should not
2633

2734
_ = x == "abc" or y == "def"

test/data/err_108.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ test/data/err_108.py:17:5 [FURB108]: Replace `x == y or x == z` with `x in (y, z
77
test/data/err_108.py:21:5 [FURB108]: Replace `x == y or z == x` with `x in (y, z)`
88
test/data/err_108.py:22:5 [FURB108]: Replace `x == y or z == y` with `y in (x, z)`
99
test/data/err_108.py:23:5 [FURB108]: Replace `x == y or y == z` with `y in (x, z)`
10+
test/data/err_108.py:26:5 [FURB108]: Replace `x == y or x == z` with `x in (y, z)`
11+
test/data/err_108.py:27:5 [FURB108]: Replace `x == y or x == z` with `x in (y, z)`
12+
test/data/err_108.py:30:5 [FURB108]: Replace `x == y or x == z` with `x in (y, z)`

0 commit comments

Comments
 (0)