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

Treat marker intersection more symmetrically #384

Merged
merged 2 commits into from
May 30, 2022
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
3 changes: 3 additions & 0 deletions src/poetry/core/version/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,9 @@ def intersect(self, other: BaseMarker) -> BaseMarker:
if other.is_empty():
return other

if isinstance(other, MarkerUnion):
return other.intersect(self)

new_markers = self._markers + [other]

return MultiMarker.of(*new_markers)
Expand Down
35 changes: 28 additions & 7 deletions tests/version/test_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,24 @@ def test_multi_marker_is_empty_is_contradictory() -> None:
assert m.is_empty()


def test_multi_complex_multi_marker_is_empty() -> None:
m1 = parse_marker(
'python_full_version >= "3.0.0" and python_full_version < "3.4.0"'
)
m2 = parse_marker(
'python_version >= "3.6" and python_full_version < "3.0.0" and python_version <'
' "3.7"'
)
m3 = parse_marker(
'python_version >= "3.6" and python_version < "3.7" and python_full_version >='
' "3.5.0"'
)

m = m1.intersect(m2.union(m3))

assert m.is_empty()


def test_multi_marker_intersect_multi() -> None:
m = parse_marker('sys_platform == "darwin" and implementation_name == "cpython"')

Expand Down Expand Up @@ -594,18 +612,21 @@ def test_marker_union_intersect_marker_union_drops_unnecessary_markers() -> None


def test_marker_union_intersect_multi_marker() -> None:
m = parse_marker('sys_platform == "darwin" or python_version < "3.4"')
m1 = parse_marker('sys_platform == "darwin" or python_version < "3.4"')
m2 = parse_marker('implementation_name == "cpython" and os_name == "Windows"')

intersection = m.intersect(
parse_marker('implementation_name == "cpython" and os_name == "Windows"')
)
assert (
str(intersection)
== 'implementation_name == "cpython" and os_name == "Windows" and sys_platform'
expected = (
'implementation_name == "cpython" and os_name == "Windows" and sys_platform'
' == "darwin" or implementation_name == "cpython" and os_name == "Windows"'
' and python_version < "3.4"'
)

intersection = m1.intersect(m2)
assert str(intersection) == expected

intersection = m2.intersect(m1)
assert str(intersection) == expected


def test_marker_union_union_with_union() -> None:
m = parse_marker('sys_platform == "darwin" or python_version < "3.4"')
Expand Down