From c444d9ca426b9fe1beb00ad4c0a23baa2aa3f7df Mon Sep 17 00:00:00 2001 From: David Hotham Date: Mon, 30 May 2022 20:51:15 +0100 Subject: [PATCH 1/2] Treat marker intersection more symmetrically prefer a union --- src/poetry/core/version/markers.py | 3 +++ tests/version/test_markers.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/poetry/core/version/markers.py b/src/poetry/core/version/markers.py index 309eb3476..448a7fcba 100644 --- a/src/poetry/core/version/markers.py +++ b/src/poetry/core/version/markers.py @@ -475,6 +475,9 @@ def intersect(self, other: BaseMarker) -> BaseMarker: if other.is_empty(): return other + if isinstance(other, MarkerUnion): + return other.intersect(self) + new_markers = self._markers + [other] return MultiMarker.of(*new_markers) diff --git a/tests/version/test_markers.py b/tests/version/test_markers.py index a3b5eab43..cfe987063 100644 --- a/tests/version/test_markers.py +++ b/tests/version/test_markers.py @@ -372,6 +372,24 @@ def test_multi_marker_is_empty_is_contradictory() -> None: assert m.is_empty() +def test_multi_complex_multi_marker_is_empty() -> None: + m1 = parse_marker( + 'python_full_version >= "3.0.0" and python_full_version < "3.4.0"' + ) + m2 = parse_marker( + 'python_version >= "3.6" and python_full_version < "3.0.0" and python_version <' + ' "3.7"' + ) + m3 = parse_marker( + 'python_version >= "3.6" and python_version < "3.7" and python_full_version >=' + ' "3.5.0"' + ) + + m = m1.intersect(m2.union(m3)) + + assert m.is_empty() + + def test_multi_marker_intersect_multi() -> None: m = parse_marker('sys_platform == "darwin" and implementation_name == "cpython"') From 55fcb73383e0add22859907e2d455352426396bd Mon Sep 17 00:00:00 2001 From: David Hotham Date: Mon, 30 May 2022 21:10:16 +0100 Subject: [PATCH 2/2] test symmetry of intersection --- tests/version/test_markers.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/version/test_markers.py b/tests/version/test_markers.py index cfe987063..f53911e2c 100644 --- a/tests/version/test_markers.py +++ b/tests/version/test_markers.py @@ -612,18 +612,21 @@ def test_marker_union_intersect_marker_union_drops_unnecessary_markers() -> None def test_marker_union_intersect_multi_marker() -> None: - m = parse_marker('sys_platform == "darwin" or python_version < "3.4"') + m1 = parse_marker('sys_platform == "darwin" or python_version < "3.4"') + m2 = parse_marker('implementation_name == "cpython" and os_name == "Windows"') - intersection = m.intersect( - parse_marker('implementation_name == "cpython" and os_name == "Windows"') - ) - assert ( - str(intersection) - == 'implementation_name == "cpython" and os_name == "Windows" and sys_platform' + expected = ( + 'implementation_name == "cpython" and os_name == "Windows" and sys_platform' ' == "darwin" or implementation_name == "cpython" and os_name == "Windows"' ' and python_version < "3.4"' ) + intersection = m1.intersect(m2) + assert str(intersection) == expected + + intersection = m2.intersect(m1) + assert str(intersection) == expected + def test_marker_union_union_with_union() -> None: m = parse_marker('sys_platform == "darwin" or python_version < "3.4"')