Skip to content

Commit 7b8f8b0

Browse files
authored
Merge pull request #293 from dimbleby/another-marker-simplification
improve detection of Any marker union
2 parents 8ce6c6c + 31e056f commit 7b8f8b0

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
@@ -561,7 +561,7 @@ def of(cls, *markers: BaseMarker) -> MarkerTypes:
561561
continue
562562

563563
if isinstance(marker, SingleMarker) and marker.name == "python_version":
564-
intersected = False
564+
included = False
565565
for i, mark in enumerate(markers):
566566
if (
567567
not isinstance(mark, SingleMarker)
@@ -570,16 +570,18 @@ def of(cls, *markers: BaseMarker) -> MarkerTypes:
570570
):
571571
continue
572572

573-
intersection = mark.constraint.union(marker.constraint)
574-
if intersection == mark.constraint:
575-
intersected = True
573+
union = mark.constraint.union(marker.constraint)
574+
if union == mark.constraint:
575+
included = True
576576
break
577-
elif intersection == marker.constraint:
577+
elif union == marker.constraint:
578578
markers[i] = marker
579-
intersected = True
579+
included = True
580580
break
581+
elif union.is_any():
582+
return AnyMarker()
581583

582-
if intersected:
584+
if included:
583585
continue
584586

585587
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)