From 376be9c4f9d27a6a948c42e9b1197097f828cbe6 Mon Sep 17 00:00:00 2001 From: cburroughs Date: Sun, 22 Dec 2024 16:54:30 -0500 Subject: [PATCH] E721: Do not compare types, use 'isinstance()' (#21791) ref #21647 --- build-support/flake8/.flake8 | 4 +--- .../pants/backend/python/util_rules/package_dists_test.py | 4 ++-- src/python/pants/engine/collection.py | 2 +- src/python/pants/option/ranked_value.py | 2 +- src/python/pants/option/subsystem.py | 2 +- src/python/pants/util/memo_test.py | 2 +- 6 files changed, 7 insertions(+), 9 deletions(-) diff --git a/build-support/flake8/.flake8 b/build-support/flake8/.flake8 index 7d6353e4d43..652d6ef705e 100644 --- a/build-support/flake8/.flake8 +++ b/build-support/flake8/.flake8 @@ -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 = diff --git a/src/python/pants/backend/python/util_rules/package_dists_test.py b/src/python/pants/backend/python/util_rules/package_dists_test.py index e04deeb9b4c..6ef620d6899 100644 --- a/src/python/pants/backend/python/util_rules/package_dists_test.py +++ b/src/python/pants/backend/python/util_rules/package_dists_test.py @@ -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: @@ -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): diff --git a/src/python/pants/engine/collection.py b/src/python/pants/engine/collection.py index b58e13069eb..51f50446d8f 100644 --- a/src/python/pants/engine/collection.py +++ b/src/python/pants/engine/collection.py @@ -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 diff --git a/src/python/pants/option/ranked_value.py b/src/python/pants/option/ranked_value.py index eb6fa13bf8d..677cdafa00f 100644 --- a/src/python/pants/option/ranked_value.py +++ b/src/python/pants/option/ranked_value.py @@ -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 diff --git a/src/python/pants/option/subsystem.py b/src/python/pants/option/subsystem.py index 2a200705973..a8e731cab24 100644 --- a/src/python/pants/option/subsystem.py +++ b/src/python/pants/option/subsystem.py @@ -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) diff --git a/src/python/pants/util/memo_test.py b/src/python/pants/util/memo_test.py index 739ea9123c5..2fed5e0b629 100644 --- a/src/python/pants/util/memo_test.py +++ b/src/python/pants/util/memo_test.py @@ -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)