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

Recognise empty marker in a complex intersection #528

Merged
merged 2 commits into from
Nov 27, 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
7 changes: 6 additions & 1 deletion src/poetry/core/version/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,12 @@ def intersect(self, other: BaseMarker) -> BaseMarker:

new_markers = self._markers + [other]

return MultiMarker.of(*new_markers)
multi = MultiMarker.of(*new_markers)

if isinstance(multi, MultiMarker):
return dnf(multi)

return multi

def union(self, other: BaseMarker) -> BaseMarker:
if isinstance(other, (SingleMarker, MultiMarker)):
Expand Down
36 changes: 36 additions & 0 deletions tests/version/test_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,42 @@ def test_single_markers_are_found_in_complex_intersection() -> None:
)


@pytest.mark.parametrize(
"marker1, marker2",
[
(
(
'(platform_system != "Windows" or platform_machine != "x86") and'
' python_version == "3.8"'
),
'platform_system == "Windows" and platform_machine == "x86"',
),
# Following example via
# https://github.com/python-poetry/poetry-plugin-export/issues/163
(
(
'python_version >= "3.8" and python_version < "3.11" and'
' (python_version > "3.9" or platform_system != "Windows" or'
' platform_machine != "x86") or python_version >= "3.11" and'
' python_version < "3.12"'
),
(
'python_version == "3.8" and platform_system == "Windows" and'
' platform_machine == "x86" or python_version == "3.9" and'
' platform_system == "Windows" and platform_machine == "x86"'
),
),
],
)
def test_empty_marker_is_found_in_complex_intersection(
marker1: str, marker2: str
) -> None:
m1 = parse_marker(marker1)
m2 = parse_marker(marker2)
assert m1.intersect(m2).is_empty()
assert m2.intersect(m1).is_empty()


@pytest.mark.parametrize(
"python_version, python_full_version, "
"expected_intersection_version, expected_union_version",
Expand Down