Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

markers: fix union of multi markers if one marker is a subset of the other marker #352

Merged
merged 1 commit into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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