Skip to content

Commit 72554d7

Browse files
committed
Refine the HiddenText.__eq__ implementation for clarity
1 parent 43c668a commit 72554d7

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/pip/_internal/utils/misc.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -541,13 +541,14 @@ def __repr__(self) -> str:
541541
def __str__(self) -> str:
542542
return self.redacted
543543

544-
# This is useful for testing.
545544
def __eq__(self, other: object) -> bool:
546-
if type(self) is not type(other) or not isinstance(other, HiddenText):
547-
return False
548-
# The string being used for redaction doesn't also have to match,
549-
# just the raw, original string.
550-
return self.secret == other.secret
545+
# Equality is particularly useful for testing.
546+
547+
if type(self) is type(other):
548+
# The string being used for redaction doesn't also have to match,
549+
# just the raw, original string.
550+
return self.secret == cast(HiddenText, other).secret
551+
return NotImplemented
551552

552553

553554
def hide_value(value: str) -> HiddenText:

0 commit comments

Comments
 (0)