Skip to content

Commit

Permalink
Add == support to FURB191
Browse files Browse the repository at this point in the history
  • Loading branch information
dosisod committed Mar 21, 2024
1 parent 85aa150 commit 714c564
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
7 changes: 4 additions & 3 deletions refurb/checks/readability/use_isinstance_bool.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ def check(node: ComparisonExpr | OpExpr, errors: list[Error]) -> None:
case OpExpr():
match extract_binary_oper("or", node):
case (
ComparisonExpr(operands=[lhs, t], operators=["is"]),
ComparisonExpr(operands=[rhs, f], operators=["is"]),
ComparisonExpr(operands=[lhs, t], operators=["is" | "==" as lhs_op]),
ComparisonExpr(operands=[rhs, f], operators=["is" | "==" as rhs_op]),
) if (
is_equivalent(lhs, rhs)
lhs_op == rhs_op
and is_equivalent(lhs, rhs)
and ((is_true(t) and is_false(f)) or (is_false(t) and is_true(f)))
):
old = stringify(node)
Expand Down
7 changes: 5 additions & 2 deletions test/data/err_191.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
_ = b is True or b is False # noqa: FURB149
_ = b is False or b is True # noqa: FURB149

_ = b == True or b == False # noqa: FURB149, FURB108
_ = b == False or b == True # noqa: FURB149, FURB108


# these should not
if b in {True}: pass # noqa: FURB171
Expand Down Expand Up @@ -68,5 +71,5 @@
_ = b is False or b is not True # noqa: FURB149

# TODO: support this later
_ = x is not True and x is not False # noqa: FURB149
_ = x is not False and x is not True # noqa: FURB149
_ = b is not True and b is not False # noqa: FURB149
_ = b is not False and b is not True # noqa: FURB149
2 changes: 2 additions & 0 deletions test/data/err_191.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ test/data/err_191.py:26:8 [FURB191]: Replace `b in {True, False}` with `isinstan
test/data/err_191.py:28:4 [FURB191]: Replace `b not in {True, False}` with `not isinstance(b, bool)`
test/data/err_191.py:30:5 [FURB191]: Replace `b is True or b is False` with `isinstance(b, bool)`
test/data/err_191.py:31:5 [FURB191]: Replace `b is False or b is True` with `isinstance(b, bool)`
test/data/err_191.py:33:5 [FURB191]: Replace `b == True or b == False` with `isinstance(b, bool)`
test/data/err_191.py:34:5 [FURB191]: Replace `b == False or b == True` with `isinstance(b, bool)`

0 comments on commit 714c564

Please sign in to comment.