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
10 changes: 5 additions & 5 deletions src/packaging/specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,11 +586,11 @@ def _compare_greater_than(self, prospective: Version, spec_str: str) -> bool:
):
return False

# Ensure that we do not allow a local version of the version mentioned
# in the specifier, which is technically greater than, to match.
if prospective.local is not None and _base_version(
prospective
) == _base_version(spec):
# Per the spec: ">V MUST NOT match a local version of the specified
# version". A "local version of V" is any version whose public part
# equals V. So >1.0a1 must not match 1.0a1+local, but must still
# match 1.0a2+local.
if prospective.local is not None and _public_version(prospective) == spec:
return False

# If we've gotten to here, it means that prospective version is both
Expand Down
22 changes: 21 additions & 1 deletion tests/test_specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,17 @@ def test_comparison_non_specifier(self) -> None:
("2!1.0", ">2.0"),
# Test some normalization rules
("2.0.5", ">2.0dev"),
# Test local versions with pre/dev/post segments and >
# (verifies _public_version keeps pre/dev/post in the guard)
("1.0+local", ">1.0.dev1"),
("4.1.0a2.dev1235+local", ">4.1.0a2.dev1234"),
("1.0a2+local", ">1.0a1"),
("1.0b2+local", ">1.0b1"),
("1.0rc2+local", ">1.0rc1"),
("1.0.post2+local", ">1.0.post1"),
("1.0.dev2+local", ">1.0.dev1"),
("1.0a1.dev2+local", ">1.0a1.dev1"),
("1.0.post1.dev2+local", ">1.0.post1.dev1"),
]
]
+ [
Expand Down Expand Up @@ -465,7 +476,16 @@ def test_comparison_non_specifier(self) -> None:
("2.0.post1", ">2"),
("2.0.post1.dev1", ">2"),
("2.0+local.version", ">2"),
("1.0+local", ">1.0.dev1"),
("4.1.0a2.dev1234+local", ">4.1.0a2.dev1234"),
# Test local versions with pre/dev/post segments and >
# (local variant of the exact spec version must not match)
("1.0a1+local", ">1.0a1"),
("1.0b1+local", ">1.0b1"),
("1.0rc1+local", ">1.0rc1"),
("1.0.post1+local", ">1.0.post1"),
("1.0.dev1+local", ">1.0.dev1"),
("1.0a1.dev1+local", ">1.0a1.dev1"),
("1.0.post1.dev1+local", ">1.0.post1.dev1"),
# Test the less than operation
("2.0.dev1", "<2"),
("2.0a1", "<2"),
Expand Down
Loading