Skip to content

Conversation

pelson
Copy link
Contributor

@pelson pelson commented Oct 15, 2025

Follows on from issues identified through #13599.

As before, intentionally targeting zero functional change.

def __eq__(self, other: Any) -> bool:
if type(self) is not type(other):
def __eq__(self, other: object) -> bool:
if type(self) is not type(other) or not isinstance(other, HiddenText):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is really about type narrowing, since mypy doesn't do that for type(self) is not type(other). The reason for the change at all comes down to the fact that self.secret == other.secret isn't recognised as a bool when other is Any.

Copy link
Contributor Author

@pelson pelson Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reflecting on this, I probably would rewrite this for clarity as:

    def __eq__(self, other: object) -> bool:
        if type(self) is type(other):
            # The string being used for redaction doesn't also have to match,
            # just the raw, original string.
            return self.secret == cast(HiddenText, other).secret
        return False

@pelson pelson changed the title [Typing} Fix minor typing of pip._internal sub packages utils, exceptions, locations, self_outdated_check [typing] Fix minor typing of pip._internal sub packages utils, exceptions, locations, self_outdated_check Oct 15, 2025
@sepehr-rs
Copy link
Member

Hi @pelson, thanks again for your contribution to pip!
This PR appears to be mostly internal again, so I’ve added the 'skip news' label.
Since these typing improvements seem related, it might be worth considering grouping similar changes into a single PR in the future, which can sometimes make reviews a bit easier for maintainers.
In any case, thanks for working on improving the typing coverage here!

@sepehr-rs sepehr-rs added the skip news Does not need a NEWS file entry (eg: trivial changes) label Oct 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news Does not need a NEWS file entry (eg: trivial changes)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants