Skip to content

Commit

Permalink
semver: fix base class checks
Browse files Browse the repository at this point in the history
  • Loading branch information
abn committed Apr 22, 2021
1 parent ab19dc2 commit 24bddf0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
3 changes: 1 addition & 2 deletions poetry/core/semver/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

if TYPE_CHECKING:
from poetry.core.semver.helpers import VersionTypes
from poetry.core.semver.version_range import VersionRange
from poetry.core.version.pep440 import LocalSegmentType


Expand Down Expand Up @@ -150,7 +149,7 @@ def __str__(self) -> str:
def __repr__(self) -> str:
return "<Version {}>".format(str(self))

def __eq__(self, other: Union["Version", "VersionRange"]) -> bool:
def __eq__(self, other: Union["Version", "VersionRangeConstraint"]) -> bool:
from poetry.core.semver.version_range import VersionRange

if isinstance(other, VersionRange):
Expand Down
22 changes: 11 additions & 11 deletions poetry/core/semver/version_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def allows_all(self, other: "VersionTypes") -> bool:
if isinstance(other, VersionUnion):
return all([self.allows_all(constraint) for constraint in other.ranges])

if isinstance(other, VersionRange):
if isinstance(other, VersionRangeConstraint):
return not other.allows_lower(self) and not other.allows_higher(self)

raise ValueError("Unknown VersionConstraint type {}.".format(other))
Expand All @@ -121,7 +121,7 @@ def allows_any(self, other: "VersionTypes") -> bool:
if isinstance(other, VersionUnion):
return any([self.allows_any(constraint) for constraint in other.ranges])

if isinstance(other, VersionRange):
if isinstance(other, VersionRangeConstraint):
return not other.is_strictly_lower(self) and not other.is_strictly_higher(
self
)
Expand All @@ -144,7 +144,7 @@ def intersect(self, other: "VersionTypes") -> "VersionTypes":

return EmptyConstraint()

if not isinstance(other, VersionRange):
if not isinstance(other, VersionRangeConstraint):
raise ValueError("Unknown VersionConstraint type {}.".format(other))

if self.allows_lower(other):
Expand Down Expand Up @@ -202,7 +202,7 @@ def union(self, other: "VersionTypes") -> "VersionTypes":

return VersionUnion.of(self, other)

if isinstance(other, VersionRange):
if isinstance(other, VersionRangeConstraint):
# If the two ranges don't overlap, we won't be able to create a single
# VersionRange for both of them.
edges_touch = (
Expand Down Expand Up @@ -261,7 +261,7 @@ def difference(self, other: "VersionTypes") -> "VersionTypes":
VersionRange(self.min, other, self.include_min, False),
VersionRange(other, self.max, False, self.include_max),
)
elif isinstance(other, VersionRange):
elif isinstance(other, VersionRangeConstraint):
if not self.allows_any(other):
return self

Expand Down Expand Up @@ -326,7 +326,7 @@ def difference(self, other: "VersionTypes") -> "VersionTypes":
raise ValueError("Unknown VersionConstraint type {}.".format(other))

def __eq__(self, other: Any) -> int:
if not isinstance(other, VersionRange):
if not isinstance(other, VersionRangeConstraint):
return False

return (
Expand All @@ -336,19 +336,19 @@ def __eq__(self, other: Any) -> int:
and self._include_max == other.include_max
)

def __lt__(self, other: "VersionRange") -> int:
def __lt__(self, other: "VersionRangeConstraint") -> int:
return self._cmp(other) < 0

def __le__(self, other: "VersionRange") -> int:
def __le__(self, other: "VersionRangeConstraint") -> int:
return self._cmp(other) <= 0

def __gt__(self, other: "VersionRange") -> int:
def __gt__(self, other: "VersionRangeConstraint") -> int:
return self._cmp(other) > 0

def __ge__(self, other: "VersionRange") -> int:
def __ge__(self, other: "VersionRangeConstraint") -> int:
return self._cmp(other) >= 0

def _cmp(self, other: "VersionRange") -> int:
def _cmp(self, other: "VersionRangeConstraint") -> int:
if self.min is None:
if other.min is None:
return self._compare_max(other)
Expand Down
6 changes: 4 additions & 2 deletions poetry/core/version/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,11 @@ def invert(self) -> MarkerTypes:
# This one is more tricky to handle
# since it's technically a multi marker
# so the inverse will be a union of inverse
from poetry.core.semver.version_range import VersionRange
from poetry.core.semver.version_range_constraint import (
VersionRangeConstraint,
)

if not isinstance(self._constraint, VersionRange):
if not isinstance(self._constraint, VersionRangeConstraint):
# The constraint must be a version range, otherwise
# it's an internal error
raise RuntimeError(
Expand Down

0 comments on commit 24bddf0

Please sign in to comment.