diff --git a/pyproject.toml b/pyproject.toml index 118e03124..8deadc67d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -104,7 +104,6 @@ module = [ 'poetry.core.packages.utils.utils', 'poetry.core.packages.dependency', 'poetry.core.packages.package', - 'poetry.core.semver.version_union', 'poetry.core.toml.exceptions', 'poetry.core.toml.file', ] diff --git a/src/poetry/core/semver/version_union.py b/src/poetry/core/semver/version_union.py index 78ccb4f9d..0a2e665cf 100644 --- a/src/poetry/core/semver/version_union.py +++ b/src/poetry/core/semver/version_union.py @@ -68,7 +68,9 @@ def of(cls, *ranges: VersionConstraint) -> VersionConstraint: ): merged.append(constraint) else: - merged[-1] = merged[-1].union(constraint) + new_constraint = merged[-1].union(constraint) + assert isinstance(new_constraint, VersionRangeConstraint) + merged[-1] = new_constraint if len(merged) == 1: return merged[0] @@ -147,7 +149,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)) - new_ranges = [] + new_ranges: list[VersionConstraint] = [] state = { "current": next(our_ranges, None), @@ -159,6 +161,7 @@ def their_next_range() -> bool: if state["their_range"]: return True + assert state["current"] is not None new_ranges.append(state["current"]) our_current = next(our_ranges, None) while our_current: @@ -169,6 +172,7 @@ def their_next_range() -> bool: def our_next_range(include_current: bool = True) -> bool: if include_current: + assert state["current"] is not None new_ranges.append(state["current"]) our_current = next(our_ranges, None) @@ -183,6 +187,7 @@ def our_next_range(include_current: bool = True) -> bool: if state["their_range"] is None: break + assert state["current"] is not None if state["their_range"].is_strictly_lower(state["current"]): if not their_next_range(): break @@ -207,6 +212,7 @@ def our_next_range(include_current: bool = True) -> bool: if not our_next_range(False): break else: + assert isinstance(difference, VersionRangeConstraint) state["current"] = difference if state["current"].allows_higher(state["their_range"]): @@ -251,7 +257,9 @@ def _exclude_single_wildcard_range_string(self) -> str: # and the one with the max is the first part idx_order = (0, 1) if self._ranges[0].max else (1, 0) one = self._ranges[idx_order[0]].max + assert one is not None two = self._ranges[idx_order[1]].min + assert two is not None # versions can have both semver and non semver parts parts_one = [ @@ -302,6 +310,9 @@ def _excludes_single_wildcard_range_check_is_valid_range( wildcard range. """ + assert one.max is not None + assert two.min is not None + max_precision = max(one.max.precision, two.min.precision) if max_precision <= 3: @@ -361,7 +372,7 @@ def _excludes_single_wildcard_range_check_is_valid_range( _padded_version_one.major, _padded_version_one.minor, _padded_version_one.patch, - *_extra, + tuple(_extra), ) )