diff --git a/src/packaging/specifiers.py b/src/packaging/specifiers.py index 13bc9bda..05ea893a 100644 --- a/src/packaging/specifiers.py +++ b/src/packaging/specifiers.py @@ -588,9 +588,9 @@ def _compare_greater_than(self, prospective: Version, spec_str: str) -> bool: # 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( + if prospective.local is not None and _public_version( prospective - ) == _base_version(spec): + ) == _public_version(spec): return False # If we've gotten to here, it means that prospective version is both diff --git a/tests/test_specifiers.py b/tests/test_specifiers.py index f5949424..2407824d 100644 --- a/tests/test_specifiers.py +++ b/tests/test_specifiers.py @@ -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"), ] ] + [ @@ -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"),