Skip to content

Commit 9cd9861

Browse files
committed
improve detection of Any marker union
1 parent 4e5207e commit 9cd9861

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/poetry/core/version/markers.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ def of(cls, *markers: BaseMarker) -> MarkerTypes:
558558
continue
559559

560560
if isinstance(marker, SingleMarker) and marker.name == "python_version":
561-
intersected = False
561+
overlapped = False
562562
for i, mark in enumerate(markers):
563563
if (
564564
not isinstance(mark, SingleMarker)
@@ -567,16 +567,18 @@ def of(cls, *markers: BaseMarker) -> MarkerTypes:
567567
):
568568
continue
569569

570-
intersection = mark.constraint.union(marker.constraint)
571-
if intersection == mark.constraint:
572-
intersected = True
570+
union = mark.constraint.union(marker.constraint)
571+
if union == mark.constraint:
572+
overlapped = True
573573
break
574-
elif intersection == marker.constraint:
574+
elif union == marker.constraint:
575575
markers[i] = marker
576-
intersected = True
576+
overlapped = True
577577
break
578+
elif union.is_any():
579+
return AnyMarker()
578580

579-
if intersected:
581+
if overlapped:
580582
continue
581583

582584
markers.append(marker)

tests/version/test_markers.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,13 @@ def test_single_marker_not_in_python_intersection():
162162
def test_single_marker_union():
163163
m = parse_marker('sys_platform == "darwin"')
164164

165-
intersection = m.union(parse_marker('implementation_name == "cpython"'))
166-
assert (
167-
str(intersection)
168-
== 'sys_platform == "darwin" or implementation_name == "cpython"'
169-
)
165+
union = m.union(parse_marker('implementation_name == "cpython"'))
166+
assert str(union) == 'sys_platform == "darwin" or implementation_name == "cpython"'
170167

171168
m = parse_marker('python_version >= "3.4"')
172169

173-
intersection = m.union(parse_marker('python_version < "3.6"'))
174-
assert str(intersection) == 'python_version >= "3.4" or python_version < "3.6"'
170+
union = m.union(parse_marker('python_version < "3.6"'))
171+
assert union.is_any()
175172

176173

177174
def test_single_marker_union_compacts_constraints():

0 commit comments

Comments
 (0)