Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A specifier of "==*" is not handled properly #307

Closed
pfmoore opened this issue May 22, 2020 · 4 comments
Closed

A specifier of "==*" is not handled properly #307

pfmoore opened this issue May 22, 2020 · 4 comments

Comments

@pfmoore
Copy link
Member

pfmoore commented May 22, 2020

This is somewhat useless, and I'm not entirely sure it's PEP 400 conformant, but the following fails:

>>> from packaging.specifiers import SpecifierSet
>>> from packaging.version import Version
>>> s = SpecifierSet("==*")
>>> s.contains(Version("1.0.0"))
False

This form of specifier is used in pip's test suite here. I'll fix the test by using a different specifier, but I think that packaging should either reject the specifier as invalid, or treat it as "always matching".

@di
Copy link
Member

di commented May 26, 2020

A specifier of ==* is not a valid Specifier:

>>> from packaging.specifiers import Specifier
>>> Specifier("==*")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/dustiningram/git/pypa/packaging/packaging/specifiers.py", line 112, in __init__
    raise InvalidSpecifier("Invalid specifier: '{0}'".format(spec))
packaging.specifiers.InvalidSpecifier: Invalid specifier: '==*'

Instead when used in a SpecifierSet it becomes a LegacySpecifier:

>>> from packaging.specifiers import SpecifierSet
>>> s = SpecifierSet("==*")
>>> s._specs
frozenset({<LegacySpecifier('==*')>})

Which means that a Version will never be contained in it, but a LegacyVersion will, but only if the version is an exact string match:

>>> from packaging.version import LegacyVersion
>>> s = SpecifierSet("==*")
>>> s.contains(LegacyVersion("*"))
True

PEP 440 says:

The specified version identifier must be in the standard format described in Version scheme, but a trailing .* is permitted on public version identifiers as described below.

where the minimum valid version is a single-digit release segment, so I would expect that particular test to use ==7.* (or ==7.1.*) instead.

@pfmoore
Copy link
Member Author

pfmoore commented May 26, 2020

Bah. Legacy stuff. I didn't even realise there was a LegacySpecifier class (I did know about LegacyVersion).

Thanks for the clarification. I had indeed changed that test as described.

I wonder whether pip's code is being inconsistent in where it allows "legacy" versions of stuff like this. Certainly we have at least one code path that was accepting a version string of "7" as matching a specifier string of "==*". Never mind, my immediate issue is addressed, and there's no bug in packaging.

@pfmoore pfmoore closed this as completed May 26, 2020
@pradyunsg pradyunsg added invalid and removed bug labels May 26, 2020
@pradyunsg
Copy link
Member

I wonder whether pip's code is being inconsistent in where it allows "legacy" versions of stuff like this.

It's not -- we just allow it everywhere. :)

@pfmoore
Copy link
Member Author

pfmoore commented May 26, 2020

Nope, the triggering case would have worked then. I think the new resolver code uses Version (i.e., non-legacy) in some places. But this is both off-topic here, and not really that important anyway 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants