diff --git a/packaging/specifiers.py b/packaging/specifiers.py index 840e08789..37030db9e 100644 --- a/packaging/specifiers.py +++ b/packaging/specifiers.py @@ -381,9 +381,12 @@ def _compare_equal(self, prospective: Version, spec: str) -> bool: if spec.endswith(".*"): # In the case of prefix matching we want to ignore local segment. prospective = Version(prospective.public) + # Convert our spec string into a Version ignoring the trailing .* + # This allows to get the normalized version string + spec_version = Version(spec[:-2]) # Split the spec out by dots, and pretend that there is an implicit # dot in between a release segment and a pre-release segment. - split_spec = _version_split(spec[:-2]) # Remove the trailing .* + split_spec = _version_split(str(spec_version)) # Split the prospective version out by dots, and pretend that there # is an implicit dot in between a release segment and a pre-release diff --git a/tests/test_specifiers.py b/tests/test_specifiers.py index 92d04eb0e..cb1f4b610 100644 --- a/tests/test_specifiers.py +++ b/tests/test_specifiers.py @@ -302,10 +302,14 @@ def test_comparison_non_specifier(self): ("2c1.post1.dev1", "==2.*"), ("2rc1", "==2.*"), ("2", "==2.*"), + ("2", "==0!2.*"), + ("0!2", "==2.*"), ("2.0", "==2.*"), ("2.0.0", "==2.*"), ("2.0.post1", "==2.0.post1.*"), ("2.0.post1.dev1", "==2.0.post1.*"), + ("2.0.rc1", "==2.0.c1.*"), + ("2.0.rc1.post1", "==2.0.c1.*"), ("2.1+local.version", "==2.1.*"), # Test the in-equality operation ("2.1", "!=2"),