Skip to content

Commit

Permalink
_ranges_for() and flatten are the same
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby committed May 29, 2022
1 parent b7187c9 commit d908cf9
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions src/poetry/core/semver/version_union.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def allows(self, version: Version) -> bool:

def allows_all(self, other: VersionConstraint) -> bool:
our_ranges = iter(self._ranges)
their_ranges = iter(self._ranges_for(other))
their_ranges = iter(other.flatten())

our_current_range = next(our_ranges, None)
their_current_range = next(their_ranges, None)
Expand All @@ -106,7 +106,7 @@ def allows_all(self, other: VersionConstraint) -> bool:

def allows_any(self, other: VersionConstraint) -> bool:
our_ranges = iter(self._ranges)
their_ranges = iter(self._ranges_for(other))
their_ranges = iter(other.flatten())

our_current_range = next(our_ranges, None)
their_current_range = next(their_ranges, None)
Expand All @@ -124,7 +124,7 @@ def allows_any(self, other: VersionConstraint) -> bool:

def intersect(self, other: VersionConstraint) -> VersionConstraint:
our_ranges = iter(self._ranges)
their_ranges = iter(self._ranges_for(other))
their_ranges = iter(other.flatten())
new_ranges = []

our_current_range = next(our_ranges, None)
Expand All @@ -148,7 +148,7 @@ def union(self, other: VersionConstraint) -> VersionConstraint:

def difference(self, other: VersionConstraint) -> VersionConstraint:
our_ranges = iter(self._ranges)
their_ranges = iter(self._ranges_for(other))
their_ranges = iter(other.flatten())
new_ranges: list[VersionConstraint] = []

state = {
Expand Down Expand Up @@ -233,20 +233,6 @@ def our_next_range(include_current: bool = True) -> bool:
def flatten(self) -> list[VersionRangeConstraint]:
return self.ranges

def _ranges_for(
self, constraint: VersionConstraint
) -> list[VersionRangeConstraint]:
if constraint.is_empty():
return []

if isinstance(constraint, VersionUnion):
return constraint.ranges

if isinstance(constraint, VersionRangeConstraint):
return [constraint]

raise ValueError(f"Unknown VersionConstraint type {constraint}")

def _exclude_single_wildcard_range_string(self) -> str:
"""
Helper method to convert this instance into a wild card range
Expand Down

0 comments on commit d908cf9

Please sign in to comment.