Skip to content

Commit

Permalink
reject empty python versions (#761)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby committed Sep 29, 2024
1 parent d066ef6 commit e85989d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/poetry/core/packages/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion src/poetry/core/packages/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
9 changes: 9 additions & 0 deletions tests/packages/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e85989d

Please sign in to comment.