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

An empty multimarker is AnyMarker, not EmptyMarker #534

Merged
merged 1 commit into from
Nov 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
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