Skip to content

Commit

Permalink
more marker simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby committed Jun 3, 2022
1 parent b0c928a commit a8bef8c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/poetry/core/version/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,9 @@ def union_simplify(self, other: BaseMarker) -> BaseMarker | None:
):
return other

if not any(isinstance(m, MarkerUnion) for m in new_markers):
return self.of(*new_markers)

elif isinstance(other, MultiMarker):
common_markers = [
marker for marker in self.markers if marker in other.markers
Expand Down Expand Up @@ -545,11 +548,14 @@ def union_simplify(self, other: BaseMarker) -> BaseMarker | None:
# 'python_version >= "3.6.2" and python_version < "3.7"' ->
#
# 'python_version >= "3.6" and python_version < "3.7"'.
conjunction = [
unions = [
m1.union(m2) for m2 in other_unique_markers for m1 in unique_markers
]
if not any(isinstance(m, MarkerUnion) for m in conjunction):
return self.of(*conjunction)
conjunction = self.of(*unions)
if not isinstance(conjunction, MultiMarker) or not any(
isinstance(m, MarkerUnion) for m in conjunction.markers
):
return conjunction

return None

Expand Down
31 changes: 31 additions & 0 deletions tests/version/test_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,37 @@ def test_multi_marker_union_multi_is_multi(
'python_version >= "3.6.2" and python_version <= "3.7"',
'python_version <= "3.7" and python_version >= "3.6"',
),
# A range covers an exact marker.
(
'python_version >= "3.6" and python_version <= "3.7"',
'python_version == "3.6"',
'python_version >= "3.6" and python_version <= "3.7"',
),
(
'python_version >= "3.6" and python_version <= "3.7"',
'python_version == "3.6" and implementation_name == "cpython"',
'python_version >= "3.6" and python_version <= "3.7"',
),
(
'python_version >= "3.6" and python_version <= "3.7"',
'python_version == "3.6.2"',
'python_version >= "3.6" and python_version <= "3.7"',
),
(
'python_version >= "3.6" and python_version <= "3.7"',
'python_version == "3.6.2" and implementation_name == "cpython"',
'python_version >= "3.6" and python_version <= "3.7"',
),
(
'python_version >= "3.6" and python_version <= "3.7"',
'python_version == "3.7"',
'python_version >= "3.6" and python_version <= "3.7"',
),
(
'python_version >= "3.6" and python_version <= "3.7"',
'python_version == "3.7" and implementation_name == "cpython"',
'python_version >= "3.6" and python_version <= "3.7"',
),
],
)
def test_version_ranges_collapse_on_union(
Expand Down

0 comments on commit a8bef8c

Please sign in to comment.