From 128c2cf41ce2690c2f96b3abe69353cea76a0d1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Tue, 20 Dec 2022 10:44:20 +0100 Subject: [PATCH] dependency: do not implicitly allow prereleases since this is not PEP 440 compliant and counterproductive (If only a prerelease fulfills a constraint, we choose it anyway. If a stable release fulfills a constraint, we shouldn't choose a prerelease if not explicitly requested.) --- src/poetry/core/packages/dependency.py | 10 ---------- tests/packages/test_dependency.py | 24 +++++++++++++----------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/poetry/core/packages/dependency.py b/src/poetry/core/packages/dependency.py index b7e8f7f79..71a1dfd07 100644 --- a/src/poetry/core/packages/dependency.py +++ b/src/poetry/core/packages/dependency.py @@ -13,7 +13,6 @@ from packaging.utils import canonicalize_name from poetry.core.constraints.generic import parse_constraint as parse_generic_constraint -from poetry.core.constraints.version import VersionRangeConstraint from poetry.core.constraints.version import parse_constraint from poetry.core.packages.dependency_group import MAIN_GROUP from poetry.core.packages.specification import PackageSpecification @@ -71,15 +70,6 @@ def __init__( groups = [MAIN_GROUP] self._groups = frozenset(groups) - - if ( - isinstance(self._constraint, VersionRangeConstraint) - and self._constraint.min - ): - allows_prereleases = ( - allows_prereleases or self._constraint.min.is_unstable() - ) - self._allows_prereleases = allows_prereleases self._python_versions = "*" diff --git a/tests/packages/test_dependency.py b/tests/packages/test_dependency.py index e47bcc182..b218444c5 100644 --- a/tests/packages/test_dependency.py +++ b/tests/packages/test_dependency.py @@ -10,20 +10,22 @@ @pytest.mark.parametrize( - "constraint,result", + "constraint", [ - ("^1.0", False), - ("^1.0.dev0", True), - ("^1.0.0", False), - ("^1.0.0.dev0", True), - ("^1.0.0.alpha0", True), - ("^1.0.0.alpha0+local", True), - ("^1.0.0.rc0+local", True), - ("^1.0.0-1", False), + "^1.0", + "^1.0.dev0", + "^1.0.0", + "^1.0.0.dev0", + "^1.0.0.alpha0", + "^1.0.0.alpha0+local", + "^1.0.0.rc0+local", + "^1.0.0-1", ], ) -def test_allows_prerelease(constraint: str, result: bool) -> None: - assert Dependency("A", constraint).allows_prereleases() == result +@pytest.mark.parametrize("allows_prereleases", [False, True]) +def test_allows_prerelease(constraint: str, allows_prereleases: bool) -> None: + dependency = Dependency("A", constraint, allows_prereleases=allows_prereleases) + assert dependency.allows_prereleases() == allows_prereleases def test_to_pep_508() -> None: