From f96a27a2f81b33a6cf9487f7027add25ede159cb Mon Sep 17 00:00:00 2001 From: David Hotham Date: Thu, 26 Sep 2024 19:29:41 +0100 Subject: [PATCH] reject empty python versions --- src/poetry/core/packages/package.py | 3 +++ src/poetry/core/packages/utils/utils.py | 4 +++- tests/packages/test_package.py | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/poetry/core/packages/package.py b/src/poetry/core/packages/package.py index 9bf89d585..4ff878ee8 100644 --- a/src/poetry/core/packages/package.py +++ b/src/poetry/core/packages/package.py @@ -278,6 +278,9 @@ def python_versions(self, value: str) -> None: except ParseConstraintError: raise ParseConstraintError(f"Invalid python versions '{value}' on {self}") + if constraint.is_empty(): + raise ParseConstraintError(f"Python versions '{value}' on {self} is empty") + self._python_versions = value self._python_constraint = constraint self._python_marker = parse_marker( diff --git a/src/poetry/core/packages/utils/utils.py b/src/poetry/core/packages/utils/utils.py index ac2ab707d..1745853c6 100644 --- a/src/poetry/core/packages/utils/utils.py +++ b/src/poetry/core/packages/utils/utils.py @@ -239,7 +239,9 @@ def create_nested_marker( marker = f'{name} == "{constraint.text}"' else: - assert isinstance(constraint, VersionRange) + assert isinstance( + constraint, VersionRange + ), f"Unexpected constraint of type {type(constraint)}" min_name = max_name = name parts = [] diff --git a/tests/packages/test_package.py b/tests/packages/test_package.py index bc187c113..84be60683 100644 --- a/tests/packages/test_package.py +++ b/tests/packages/test_package.py @@ -658,3 +658,12 @@ def test_package_invalid_python_versions() -> None: expected = "Invalid python versions '>=3.6.y' on foo (1.2.3)" assert str(exc_info.value) == expected + + +def test_package_empty_python_versions() -> None: + package = Package("foo", "1.2.3") + with pytest.raises(ParseConstraintError) as exc_info: + package.python_versions = "~2.7, >=3.4, <3.8" + + expected = "Python versions '~2.7, >=3.4, <3.8' on foo (1.2.3) is empty" + assert str(exc_info.value) == expected