From 31e056ff7f6f4d0177e902aaca674c0b80d9c0e9 Mon Sep 17 00:00:00 2001 From: David Hotham Date: Sat, 12 Feb 2022 15:18:36 +0000 Subject: [PATCH] improve detection of Any marker union --- src/poetry/core/version/markers.py | 16 +++++++++------- tests/version/test_markers.py | 11 ++++------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/poetry/core/version/markers.py b/src/poetry/core/version/markers.py index 7b2e98627..897a672ab 100644 --- a/src/poetry/core/version/markers.py +++ b/src/poetry/core/version/markers.py @@ -558,7 +558,7 @@ def of(cls, *markers: BaseMarker) -> MarkerTypes: continue if isinstance(marker, SingleMarker) and marker.name == "python_version": - intersected = False + included = False for i, mark in enumerate(markers): if ( not isinstance(mark, SingleMarker) @@ -567,16 +567,18 @@ def of(cls, *markers: BaseMarker) -> MarkerTypes: ): continue - intersection = mark.constraint.union(marker.constraint) - if intersection == mark.constraint: - intersected = True + union = mark.constraint.union(marker.constraint) + if union == mark.constraint: + included = True break - elif intersection == marker.constraint: + elif union == marker.constraint: markers[i] = marker - intersected = True + included = True break + elif union.is_any(): + return AnyMarker() - if intersected: + if included: continue markers.append(marker) diff --git a/tests/version/test_markers.py b/tests/version/test_markers.py index 123206e4e..7cff233a6 100644 --- a/tests/version/test_markers.py +++ b/tests/version/test_markers.py @@ -162,16 +162,13 @@ def test_single_marker_not_in_python_intersection(): def test_single_marker_union(): m = parse_marker('sys_platform == "darwin"') - intersection = m.union(parse_marker('implementation_name == "cpython"')) - assert ( - str(intersection) - == 'sys_platform == "darwin" or implementation_name == "cpython"' - ) + union = m.union(parse_marker('implementation_name == "cpython"')) + assert str(union) == 'sys_platform == "darwin" or implementation_name == "cpython"' m = parse_marker('python_version >= "3.4"') - intersection = m.union(parse_marker('python_version < "3.6"')) - assert str(intersection) == 'python_version >= "3.4" or python_version < "3.6"' + union = m.union(parse_marker('python_version < "3.6"')) + assert union.is_any() def test_single_marker_union_compacts_constraints():