From 86bfb8eb3056861c0e30321ace720337e4877359 Mon Sep 17 00:00:00 2001 From: David Hotham Date: Sat, 26 Nov 2022 15:59:48 +0000 Subject: [PATCH 1/2] Recognise empty marker in a complex intersection --- src/poetry/core/version/markers.py | 7 ++++++- tests/version/test_markers.py | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/poetry/core/version/markers.py b/src/poetry/core/version/markers.py index 7f1b642ab..8915d53c9 100644 --- a/src/poetry/core/version/markers.py +++ b/src/poetry/core/version/markers.py @@ -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)): diff --git a/tests/version/test_markers.py b/tests/version/test_markers.py index 385afe895..1afec3714 100644 --- a/tests/version/test_markers.py +++ b/tests/version/test_markers.py @@ -1311,6 +1311,16 @@ def test_single_markers_are_found_in_complex_intersection() -> None: ) +def test_empty_marker_is_found_in_complex_intersection() -> None: + m1 = parse_marker( + '(platform_system != "Windows" or platform_machine != "x86") and python_version' + ' == "3.8"' + ) + m2 = parse_marker('platform_system == "Windows" and platform_machine == "x86"') + intersection = m1.intersect(m2) + assert intersection.is_empty() + + @pytest.mark.parametrize( "python_version, python_full_version, " "expected_intersection_version, expected_union_version", From 466090c38a24bd53c8d9a524f1eb33026d5687cb Mon Sep 17 00:00:00 2001 From: David Hotham Date: Sun, 27 Nov 2022 11:52:52 +0000 Subject: [PATCH 2/2] additional testcases --- tests/version/test_markers.py | 42 ++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/tests/version/test_markers.py b/tests/version/test_markers.py index 1afec3714..345dca1e6 100644 --- a/tests/version/test_markers.py +++ b/tests/version/test_markers.py @@ -1311,14 +1311,40 @@ def test_single_markers_are_found_in_complex_intersection() -> None: ) -def test_empty_marker_is_found_in_complex_intersection() -> None: - m1 = parse_marker( - '(platform_system != "Windows" or platform_machine != "x86") and python_version' - ' == "3.8"' - ) - m2 = parse_marker('platform_system == "Windows" and platform_machine == "x86"') - intersection = m1.intersect(m2) - assert intersection.is_empty() +@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(