Skip to content

Commit

Permalink
markers: fix union of multi markers if one marker is a subset of the …
Browse files Browse the repository at this point in the history
…other marker
  • Loading branch information
radoering authored and neersighted committed May 11, 2022
1 parent 79ba1d8 commit 5d5f6ae
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/poetry/core/version/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,11 @@ def union_simplify(self, other: BaseMarker) -> BaseMarker | None:
other_markers = set(other.markers)
common_markers = markers & other_markers
unique_markers = markers - common_markers
if not unique_markers:
return self
other_unique_markers = other_markers - common_markers
if not other_unique_markers:
return other
if common_markers:
unique_union = self.of(*unique_markers).union(
self.of(*other_unique_markers)
Expand Down
31 changes: 24 additions & 7 deletions tests/version/test_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,13 +445,30 @@ def test_multi_marker_union_multi_is_single_marker() -> None:
assert str(m2.union(m)) == 'python_version >= "3"'


def test_multi_marker_union_multi_is_multi() -> None:
m = parse_marker('python_version >= "3" and sys_platform == "win32"')
m2 = parse_marker(
'python_version >= "3" and sys_platform != "win32" and sys_platform != "linux"'
)
assert str(m.union(m2)) == 'python_version >= "3" and sys_platform != "linux"'
assert str(m2.union(m)) == 'python_version >= "3" and sys_platform != "linux"'
@pytest.mark.parametrize(
"marker1, marker2, expected",
[
(
'python_version >= "3" and sys_platform == "win32"',
'python_version >= "3" and sys_platform != "win32" and sys_platform !='
' "linux"',
'python_version >= "3" and sys_platform != "linux"',
),
(
'python_version >= "3.8" and python_version < "4.0" and sys_platform =='
' "win32"',
'python_version >= "3.8" and python_version < "4.0"',
'python_version >= "3.8" and python_version < "4.0"',
),
],
)
def test_multi_marker_union_multi_is_multi(
marker1: str, marker2: str, expected: str
) -> None:
m1 = parse_marker(marker1)
m2 = parse_marker(marker2)
assert str(m1.union(m2)) == expected
assert str(m2.union(m1)) == expected


def test_multi_marker_union_with_union() -> None:
Expand Down

0 comments on commit 5d5f6ae

Please sign in to comment.