Skip to content

Type all comparison/operators dunders #4583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions pkg_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ def __iter__(self) -> Iterator[str]:
if self[key]:
yield key

def __iadd__(self, other: Distribution | Environment):
def __iadd__(self, other: Distribution | Environment) -> Self:
"""In-place addition of a distribution or environment"""
if isinstance(other, Distribution):
self.add(other)
Expand All @@ -1309,7 +1309,7 @@ def __iadd__(self, other: Distribution | Environment):
raise TypeError("Can't add %r to environment" % (other,))
return self

def __add__(self, other: Distribution | Environment):
def __add__(self, other: Distribution | Environment) -> Self:
"""Add an environment or distribution to an environment"""
new = self.__class__([], platform=None, python=None)
for env in self, other:
Expand Down Expand Up @@ -2355,7 +2355,7 @@ class NoDists:
[]
"""

def __bool__(self):
def __bool__(self) -> Literal[False]:
return False

def __call__(self, fullpath):
Expand Down Expand Up @@ -2954,28 +2954,28 @@ def hashcmp(self):
self.platform or '',
)

def __hash__(self):
def __hash__(self) -> int:
return hash(self.hashcmp)

def __lt__(self, other: Distribution):
def __lt__(self, other: Distribution) -> bool:
return self.hashcmp < other.hashcmp

def __le__(self, other: Distribution):
def __le__(self, other: Distribution) -> bool:
return self.hashcmp <= other.hashcmp

def __gt__(self, other: Distribution):
def __gt__(self, other: Distribution) -> bool:
return self.hashcmp > other.hashcmp

def __ge__(self, other: Distribution):
def __ge__(self, other: Distribution) -> bool:
return self.hashcmp >= other.hashcmp

def __eq__(self, other: object):
def __eq__(self, other: object) -> bool:
if not isinstance(other, self.__class__):
# It's not a Distribution, so they are not equal
return False
return self.hashcmp == other.hashcmp

def __ne__(self, other: object):
def __ne__(self, other: object) -> bool:
return not self == other

# These properties have to be lazy so that we don't have to load any
Expand Down Expand Up @@ -3472,10 +3472,10 @@ def __init__(self, requirement_string: str):
)
self.__hash = hash(self.hashCmp)

def __eq__(self, other: object):
def __eq__(self, other: object) -> bool:
return isinstance(other, Requirement) and self.hashCmp == other.hashCmp

def __ne__(self, other):
def __ne__(self, other: object) -> bool:
return not self == other

def __contains__(
Expand All @@ -3497,7 +3497,7 @@ def __contains__(
prereleases=True,
)

def __hash__(self):
def __hash__(self) -> int:
return self.__hash

def __repr__(self):
Expand Down
Loading