Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve detection of Any marker union #293

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/poetry/core/version/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
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