Skip to content

Commit 8ce6c6c

Browse files
authored
Merge pull request #282 from dimbleby/marker-simplifications
Marker simplifications
2 parents 4e5207e + 9743333 commit 8ce6c6c

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

src/poetry/core/version/markers.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,8 @@ def of(cls, *markers: MarkerTypes) -> MarkerTypes:
449449
if any(m.is_empty() for m in new_markers) or not new_markers:
450450
return EmptyMarker()
451451

452-
if len(new_markers) == 1 and new_markers[0].is_any():
453-
return AnyMarker()
452+
if len(new_markers) == 1:
453+
return new_markers[0]
454454

455455
return MultiMarker(*new_markers)
456456

@@ -470,6 +470,9 @@ def intersect(self, other: MarkerTypes) -> MarkerTypes:
470470
return MultiMarker.of(*new_markers)
471471

472472
def union(self, other: MarkerTypes) -> MarkerTypes:
473+
if other in self._markers:
474+
return other
475+
473476
if isinstance(other, (SingleMarker, MultiMarker)):
474477
return MarkerUnion.of(self, other)
475478

tests/version/test_markers.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,13 +685,13 @@ def test_without_extras(marker: str, expected: str):
685685
(
686686
'python_version >= "3.6" and (extra == "foo" or extra == "bar")',
687687
"python_version",
688-
'(extra == "foo" or extra == "bar")',
688+
'extra == "foo" or extra == "bar"',
689689
),
690690
(
691691
'python_version >= "3.6" and (extra == "foo" or extra == "bar") or'
692692
' implementation_name == "pypy"',
693693
"python_version",
694-
'(extra == "foo" or extra == "bar") or implementation_name == "pypy"',
694+
'extra == "foo" or extra == "bar" or implementation_name == "pypy"',
695695
),
696696
(
697697
'python_version >= "3.6" and extra == "foo" or implementation_name =='
@@ -705,6 +705,11 @@ def test_without_extras(marker: str, expected: str):
705705
"implementation_name",
706706
'python_version >= "3.6" or extra == "foo" or extra == "bar"',
707707
),
708+
(
709+
'extra == "foo" and python_version >= "3.6" or python_version >= "3.6"',
710+
"extra",
711+
'python_version >= "3.6"',
712+
),
708713
],
709714
)
710715
def test_exclude(marker: str, excluded: str, expected: str):
@@ -728,7 +733,7 @@ def test_exclude(marker: str, excluded: str, expected: str):
728733
(
729734
'python_version >= "3.6" and (extra == "foo" or extra == "bar")',
730735
["extra"],
731-
'(extra == "foo" or extra == "bar")',
736+
'extra == "foo" or extra == "bar"',
732737
),
733738
(
734739
'python_version >= "3.6" and (extra == "foo" or extra == "bar") or'
@@ -768,6 +773,14 @@ def test_union_of_a_single_marker_is_the_single_marker():
768773
assert SingleMarker("python_version", ">= 2.7") == union
769774

770775

776+
def test_union_of_multi_with_a_containing_single():
777+
single = parse_marker('python_version >= "2.7"')
778+
multi = parse_marker('python_version >= "2.7" and extra == "foo"')
779+
union = multi.union(single)
780+
781+
assert union == single
782+
783+
771784
@pytest.mark.parametrize(
772785
"marker, inverse",
773786
[

0 commit comments

Comments
 (0)