Skip to content

Commit

Permalink
Merge pull request #293 from dimbleby/another-marker-simplification
Browse files Browse the repository at this point in the history
improve detection of Any marker union
  • Loading branch information
finswimmer committed Feb 26, 2022
2 parents 8ce6c6c + 31e056f commit 7b8f8b0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
16 changes: 9 additions & 7 deletions src/poetry/core/version/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,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)
Expand All @@ -570,16 +570,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)
Expand Down
11 changes: 4 additions & 7 deletions tests/version/test_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 7b8f8b0

Please sign in to comment.