diff --git a/src/poetry/core/packages/package.py b/src/poetry/core/packages/package.py index 62819e611..123d8075a 100644 --- a/src/poetry/core/packages/package.py +++ b/src/poetry/core/packages/package.py @@ -15,6 +15,7 @@ from poetry.core.packages.dependency_group import MAIN_GROUP from poetry.core.packages.specification import PackageSpecification from poetry.core.packages.utils.utils import create_nested_marker +from poetry.core.packages.utils.utils import get_python_constraint_from_marker from poetry.core.semver.helpers import parse_constraint from poetry.core.version.markers import parse_marker @@ -255,10 +256,11 @@ def python_versions(self) -> str: @python_versions.setter def python_versions(self, value: str) -> None: self._python_versions = value - self._python_constraint = parse_constraint(value) + constraint = parse_constraint(value) self._python_marker = parse_marker( - create_nested_marker("python_version", self._python_constraint) + create_nested_marker("python_version", constraint) ) + self._python_constraint = get_python_constraint_from_marker(self._python_marker) @property def python_constraint(self) -> VersionConstraint: diff --git a/tests/packages/test_package.py b/tests/packages/test_package.py index b9d956caf..3ef9af26f 100644 --- a/tests/packages/test_package.py +++ b/tests/packages/test_package.py @@ -527,3 +527,14 @@ def test_package_pep592_yanked( assert package.yanked == expected_yanked assert package.yanked_reason == expected_yanked_reason + + +def test_python_versions_are_normalized() -> None: + package = Package("foo", "1.2.3") + package.python_versions = ">3.6,<=3.10" + + assert ( + str(package.python_marker) + == 'python_version > "3.6" and python_version <= "3.10"' + ) + assert str(package.python_constraint) == ">=3.7,<3.11"