I would expect the following version specifier to fail
requests>=1.0.0<2.0.0
But it doesn't, instead it installs requests 2.21.x!
Unfortunately this is not a bug, 1.0.0<2.0.0 is a valid, albeit "legacy" version:
>>> from packaging.requirements import Requirement
>>> req = Requirement('requests>=1.0.0<2.0.0')
>>> list(req.specifier)
[<LegacySpecifier('>=1.0.0<2.0.0')>]
>>> req.specifier.contains('2.21.0')
True
See here: https://github.com/pypa/packaging/blob/master/packaging/specifiers.py#L207-L219
Yeah, I agree with @di here. I think the best we could do is raise a warning that a given specifier is not PEP 440 compliant, but that has two problems:
Perhaps a warning or error would be appropriate in pip if the requirement specified contains non-PEP440 version identifiers but the project only has published PEP 440-compliant versions? setuptools doesn't have enough information to detect that, but pip might, and that's more likely than not to be a legitimate error.
Perhaps it's time to just deprecate "legacy" versions? PEP 440 was created just over 6 years ago.
Most helpful comment
Perhaps it's time to just deprecate "legacy" versions? PEP 440 was created just over 6 years ago.