Skip to content

Commit

Permalink
an empty multimarker is AnyMarker, not EmptyMarker
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby committed Nov 29, 2022
1 parent d98aa6e commit 5f8e0d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/poetry/core/version/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,12 @@ def of(cls, *markers: BaseMarker) -> BaseMarker:

new_markers.append(marker)

if any(m.is_empty() for m in new_markers) or not new_markers:
if any(m.is_empty() for m in new_markers):
return EmptyMarker()

if not new_markers:
return AnyMarker()

if len(new_markers) == 1:
return new_markers[0]

Expand Down Expand Up @@ -577,6 +580,9 @@ def only(self, *marker_names: str) -> BaseMarker:
if not marker.is_empty():
new_markers.append(marker)

if not new_markers:
return EmptyMarker()

return self.of(*new_markers)

def invert(self) -> BaseMarker:
Expand Down
9 changes: 9 additions & 0 deletions tests/version/test_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,14 @@ def test_multi_complex_multi_marker_is_empty() -> None:
assert m.is_empty()


def test_multi_marker_is_any() -> None:
m1 = parse_marker('python_version != "3.6" or python_version == "3.6"')
m2 = parse_marker('python_version != "3.7" or python_version == "3.7"')

assert m1.intersect(m2).is_any()
assert m2.intersect(m1).is_any()


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

Expand Down Expand Up @@ -933,6 +941,7 @@ def test_without_extras(marker: str, expected: str) -> None:
[
('python_version >= "3.6"', "implementation_name", 'python_version >= "3.6"'),
('python_version >= "3.6"', "python_version", "*"),
('python_version >= "3.6" and python_version < "3.11"', "python_version", "*"),
(
'python_version >= "3.6" and extra == "foo"',
"extra",
Expand Down

0 comments on commit 5f8e0d4

Please sign in to comment.