Skip to content

Commit

Permalink
E721: Do not compare types, use 'isinstance()'
Browse files Browse the repository at this point in the history
  • Loading branch information
cburroughs committed Dec 20, 2024
1 parent 627d533 commit 8290d3e
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 9 deletions.
4 changes: 1 addition & 3 deletions build-support/flake8/.flake8
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ extend-ignore:
# Implicitly concatenated bytes literals over multiple lines
NIC102,
# Unnecessary dict call - rewrite as a literal
C408,
# Temporarily exclude during Python upgrade
E721
C408

[flake8:local-plugins]
extension =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def assert_chroot_error(
)
ex = excinfo.value
assert len(ex.wrapped_exceptions) == 1
assert type(ex.wrapped_exceptions[0]) == exc_cls
assert type(ex.wrapped_exceptions[0]) is exc_cls


def test_use_existing_setup_script(chroot_rule_runner) -> None:
Expand Down Expand Up @@ -1167,7 +1167,7 @@ def assert_owner_error(rule_runner, owned: Address, exc_cls: type[Exception]):
)
ex = excinfo.value
assert len(ex.wrapped_exceptions) == 1
assert type(ex.wrapped_exceptions[0]) == exc_cls
assert type(ex.wrapped_exceptions[0]) is exc_cls


def assert_no_owner(rule_runner: PythonRuleRunner, owned: Address):
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/engine/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __getitem__(self, index: int | slice) -> T | Collection[T]: # noqa: F811
def __eq__(self, other: Any) -> bool:
if self is other:
return True
return type(self) == type(other) and super().__eq__(other)
return type(self) is type(other) and super().__eq__(other)

def __ne__(self, other: Any) -> bool:
# We must explicitly override to provide the inverse of _our_ __eq__ and not get the
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/option/ranked_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __new__(cls, rank: int, display: str) -> Rank:
return member

def __lt__(self, other: Any) -> bool:
if type(other) != Rank:
if type(other) != Rank: # noqa: E721
return NotImplemented
return self._rank < other._rank

Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/option/subsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def __init__(self, options: OptionValueContainer) -> None:
self.options = options

def __eq__(self, other: Any) -> bool:
if type(self) != type(other):
if type(self) != type(other): # noqa: E721
return False
return bool(self.options == other.options)

Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/util/memo_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def __hash__(self):
return hash(type)

def __eq__(self, other):
return type(self) == type(other)
return type(self) == type(other) # noqa: E721

foo1 = Foo(3)
foo2 = Foo(4)
Expand Down

0 comments on commit 8290d3e

Please sign in to comment.