From 043aee804424155bab1325decd50c9e4c54f02b5 Mon Sep 17 00:00:00 2001 From: David Hotham Date: Wed, 13 Jul 2022 17:25:03 +0100 Subject: [PATCH] fix without_extras() for marker unions (#415) * fix without_extras() for marker unions * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- src/poetry/core/version/markers.py | 6 ++++-- tests/version/test_markers.py | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/poetry/core/version/markers.py b/src/poetry/core/version/markers.py index 9eebe0017..1b5630e55 100644 --- a/src/poetry/core/version/markers.py +++ b/src/poetry/core/version/markers.py @@ -734,9 +734,11 @@ def exclude(self, marker_name: str) -> BaseMarker: continue marker = m.exclude(marker_name) + new_markers.append(marker) - if not marker.is_empty(): - new_markers.append(marker) + if not new_markers: + # All markers were the excluded marker. + return AnyMarker() return self.of(*new_markers) diff --git a/tests/version/test_markers.py b/tests/version/test_markers.py index 9bf900c47..364cbed88 100644 --- a/tests/version/test_markers.py +++ b/tests/version/test_markers.py @@ -905,6 +905,8 @@ def test_parse_version_like_markers(marker: str, env: dict[str, str]) -> None: ' "pypy" or extra == "bar"', 'python_version >= "3.6" or implementation_name == "pypy"', ), + ('extra == "foo"', ""), + ('extra == "foo" or extra == "bar"', ""), ], ) def test_without_extras(marker: str, expected: str) -> None: