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

reject empty python versions #761

Merged
merged 1 commit into from
Sep 29, 2024
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
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
Loading