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