Skip to content
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
1 change: 1 addition & 0 deletions docs/changelog/217.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Exclude prereleases of the final version named by an exclusive upper bound, such as ``<3.12.0`` rejecting ``3.12.0rc1``.
8 changes: 8 additions & 0 deletions src/python_discovery/_specifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ def _check_standard(self, candidate: SimpleVersion) -> bool:
return str(candidate) == str(self.version)
if self.operator == "~=":
return self._check_compatible_release(candidate)
# PEP 440 excludes prereleases of a final release named by an exclusive upper bound.
if (
self.operator == "<"
and candidate.pre_type is not None
and self.version.pre_type is None
and candidate.release == self.version.release
):
return False
cmp_ops = {
"==": operator.eq,
"!=": operator.ne,
Expand Down
1 change: 1 addition & 0 deletions tests/test_py_info_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ def test_satisfies_version_specifier_unparsable_version() -> None:
pytest.param(VersionInfo(3, 15, 0, "alpha", 6), ">=3.15.0", False, id="prerelease_not_match_full_precision"),
pytest.param(VersionInfo(3, 15, 0, "alpha", 5), "<3.15.0a6", True, id="earlier_prerelease_less_than"),
pytest.param(VersionInfo(3, 15, 0, "alpha", 6), "<3.15.0a6", False, id="prerelease_not_less_than_itself"),
pytest.param(VersionInfo(3, 12, 0, "candidate", 1), "<3.12.0", False, id="prerelease_not_below_final_bound"),
pytest.param(VersionInfo(3, 15, 0, "alpha", 6), ">=3.15.0a6", True, id="prerelease_match_itself"),
pytest.param(VersionInfo(3, 15, 0, "alpha", 6), ">=3.15.0a7", False, id="prerelease_not_match_later"),
pytest.param(VersionInfo(3, 15, 0, "final", 0), ">=3.15.0a6", True, id="final_greater_than_prerelease"),
Expand Down
5 changes: 5 additions & 0 deletions tests/test_specifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ def test_specifier_parse_wildcard() -> None:
pytest.param(">3.12", "3.12.0", False, id="gt-equal"),
pytest.param("<3.12", "3.11.0", True, id="lt-below"),
pytest.param("<3.12", "3.12.0", False, id="lt-equal"),
pytest.param("<3.12", "3.12.0rc1", False, id="lt-boundary-prerelease-two-part"),
pytest.param("<3.12.0", "3.12.0rc1", False, id="lt-boundary-prerelease-three-part"),
pytest.param("<3.12.0rc2", "3.12.0rc1", True, id="lt-explicit-prerelease-bound"),
pytest.param("<3.12.0", "3.11.9rc1", True, id="lt-lower-release-prerelease"),
pytest.param("<=3.12.0", "3.12.0rc1", True, id="lte-boundary-prerelease"),
pytest.param("==3.12.0", "3.12.0", True, id="eq-match"),
pytest.param("==3.12.0", "3.12.1", False, id="eq-no-match"),
pytest.param("!=3.12.0", "3.12.0", False, id="ne-match"),
Expand Down