Skip to content

Commit 15dd20f

Browse files
committed
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.)
1 parent 7f4070f commit 15dd20f

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

src/poetry/core/packages/dependency.py

-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from packaging.utils import canonicalize_name
1414

1515
from poetry.core.constraints.generic import parse_constraint as parse_generic_constraint
16-
from poetry.core.constraints.version import VersionRangeConstraint
1716
from poetry.core.constraints.version import parse_constraint
1817
from poetry.core.packages.dependency_group import MAIN_GROUP
1918
from poetry.core.packages.specification import PackageSpecification
@@ -71,15 +70,6 @@ def __init__(
7170
groups = [MAIN_GROUP]
7271

7372
self._groups = frozenset(groups)
74-
75-
if (
76-
isinstance(self._constraint, VersionRangeConstraint)
77-
and self._constraint.min
78-
):
79-
allows_prereleases = (
80-
allows_prereleases or self._constraint.min.is_unstable()
81-
)
82-
8373
self._allows_prereleases = allows_prereleases
8474

8575
self._python_versions = "*"

tests/packages/test_dependency.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@
1010

1111

1212
@pytest.mark.parametrize(
13-
"constraint,result",
13+
"constraint",
1414
[
15-
("^1.0", False),
16-
("^1.0.dev0", True),
17-
("^1.0.0", False),
18-
("^1.0.0.dev0", True),
19-
("^1.0.0.alpha0", True),
20-
("^1.0.0.alpha0+local", True),
21-
("^1.0.0.rc0+local", True),
22-
("^1.0.0-1", False),
15+
"^1.0",
16+
"^1.0.dev0",
17+
"^1.0.0",
18+
"^1.0.0.dev0",
19+
"^1.0.0.alpha0",
20+
"^1.0.0.alpha0+local",
21+
"^1.0.0.rc0+local",
22+
"^1.0.0-1",
2323
],
2424
)
25-
def test_allows_prerelease(constraint: str, result: bool) -> None:
26-
assert Dependency("A", constraint).allows_prereleases() == result
25+
@pytest.mark.parametrize("allows_prereleases", [False, True])
26+
def test_allows_prerelease(constraint: str, allows_prereleases: bool) -> None:
27+
dependency = Dependency("A", constraint, allows_prereleases=allows_prereleases)
28+
assert dependency.allows_prereleases() == allows_prereleases
2729

2830

2931
def test_to_pep_508() -> None:

0 commit comments

Comments
 (0)