diff --git a/refurb/checks/readability/use_isinstance_bool.py b/refurb/checks/readability/use_isinstance_bool.py index c557d8a..69b1714 100644 --- a/refurb/checks/readability/use_isinstance_bool.py +++ b/refurb/checks/readability/use_isinstance_bool.py @@ -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) diff --git a/test/data/err_191.py b/test/data/err_191.py index c8aa3b2..0655a0c 100644 --- a/test/data/err_191.py +++ b/test/data/err_191.py @@ -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 @@ -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 diff --git a/test/data/err_191.txt b/test/data/err_191.txt index 9d30e2b..db54013 100644 --- a/test/data/err_191.txt +++ b/test/data/err_191.txt @@ -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)`