diff --git a/src/poetry/core/version/markers.py b/src/poetry/core/version/markers.py index 911a13752..67b25d122 100644 --- a/src/poetry/core/version/markers.py +++ b/src/poetry/core/version/markers.py @@ -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) diff --git a/tests/version/test_markers.py b/tests/version/test_markers.py index 992b6d2fb..95880cd13 100644 --- a/tests/version/test_markers.py +++ b/tests/version/test_markers.py @@ -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: