Skip to content

Commit 9743333

Browse files
committed
simplify obvious unions
1 parent 6e82361 commit 9743333

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

src/poetry/core/version/markers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,14 @@ def test_union_of_a_single_marker_is_the_single_marker():
773773
assert SingleMarker("python_version", ">= 2.7") == union
774774

775775

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+
776784
@pytest.mark.parametrize(
777785
"marker, inverse",
778786
[

0 commit comments

Comments
 (0)