Skip to content

Commit

Permalink
Treat marker intersection more symmetrically
Browse files Browse the repository at this point in the history
prefer a union
  • Loading branch information
dimbleby authored and neersighted committed May 30, 2022
1 parent e016bd3 commit 7436e6c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
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
18 changes: 18 additions & 0 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

0 comments on commit 7436e6c

Please sign in to comment.