Skip to content

Commit a8bef8c

Browse files
committed
more marker simplifications
1 parent b0c928a commit a8bef8c

2 files changed

Lines changed: 40 additions & 3 deletions

File tree

src/poetry/core/version/markers.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,9 @@ def union_simplify(self, other: BaseMarker) -> BaseMarker | None:
513513
):
514514
return other
515515

516+
if not any(isinstance(m, MarkerUnion) for m in new_markers):
517+
return self.of(*new_markers)
518+
516519
elif isinstance(other, MultiMarker):
517520
common_markers = [
518521
marker for marker in self.markers if marker in other.markers
@@ -545,11 +548,14 @@ def union_simplify(self, other: BaseMarker) -> BaseMarker | None:
545548
# 'python_version >= "3.6.2" and python_version < "3.7"' ->
546549
#
547550
# 'python_version >= "3.6" and python_version < "3.7"'.
548-
conjunction = [
551+
unions = [
549552
m1.union(m2) for m2 in other_unique_markers for m1 in unique_markers
550553
]
551-
if not any(isinstance(m, MarkerUnion) for m in conjunction):
552-
return self.of(*conjunction)
554+
conjunction = self.of(*unions)
555+
if not isinstance(conjunction, MultiMarker) or not any(
556+
isinstance(m, MarkerUnion) for m in conjunction.markers
557+
):
558+
return conjunction
553559

554560
return None
555561

tests/version/test_markers.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,37 @@ def test_multi_marker_union_multi_is_multi(
535535
'python_version >= "3.6.2" and python_version <= "3.7"',
536536
'python_version <= "3.7" and python_version >= "3.6"',
537537
),
538+
# A range covers an exact marker.
539+
(
540+
'python_version >= "3.6" and python_version <= "3.7"',
541+
'python_version == "3.6"',
542+
'python_version >= "3.6" and python_version <= "3.7"',
543+
),
544+
(
545+
'python_version >= "3.6" and python_version <= "3.7"',
546+
'python_version == "3.6" and implementation_name == "cpython"',
547+
'python_version >= "3.6" and python_version <= "3.7"',
548+
),
549+
(
550+
'python_version >= "3.6" and python_version <= "3.7"',
551+
'python_version == "3.6.2"',
552+
'python_version >= "3.6" and python_version <= "3.7"',
553+
),
554+
(
555+
'python_version >= "3.6" and python_version <= "3.7"',
556+
'python_version == "3.6.2" and implementation_name == "cpython"',
557+
'python_version >= "3.6" and python_version <= "3.7"',
558+
),
559+
(
560+
'python_version >= "3.6" and python_version <= "3.7"',
561+
'python_version == "3.7"',
562+
'python_version >= "3.6" and python_version <= "3.7"',
563+
),
564+
(
565+
'python_version >= "3.6" and python_version <= "3.7"',
566+
'python_version == "3.7" and implementation_name == "cpython"',
567+
'python_version >= "3.6" and python_version <= "3.7"',
568+
),
538569
],
539570
)
540571
def test_version_ranges_collapse_on_union(

0 commit comments

Comments
 (0)