Skip to content

NormalizedMatcher fails to parse dev versions like 0.8.1dev #200

@con-f-use

Description

@con-f-use

Describe the bug

dislib.version.NormaizeMatcher errors when called with something like 0.8.1dev. I.e. development version specifiers that either omit the trailing number or the dot separator.

PEP 440 specifies that development release separators may omit the separator and number entirely:

Development release separators

Development releases allow a ., -, or a _ separator as well as omitting the separator all together. The normal form of this is with the . separator. This allows versions such as 1.2-dev2 or 1.2dev2 which normalize to 1.2.dev2.
Implicit development release number

Development releases allow omitting the numeral in which case it is implicitly assumed to be 0. The normal form for this is to include the 0 explicitly. This allows versions such as 1.2.dev which is normalized to 1.2.dev0.

To Reproduce

$ python -c 'import distlib, distlib.version; print(f"{distlib.__version__=}"); print(distlib.version.NormalizedMatcher("mypackage<0.8.1dev"))'
distlib.__version__='0.3.6'
Traceback (most recent call last):
 File "<string>", line 1, in <module>
 File "/tmp/bla/.direnv/python-3.10.10/lib/python3.10/site-packages/distlib/version.py", line 125, in __init__
   vn, prefix = self.version_class(s), False
 File "/tmp/bla/.direnv/python-3.10.10/lib/python3.10/site-packages/distlib/version.py", line 33, in __init__
   self._parts = parts = self.parse(s)
 File "/tmp/bla/.direnv/python-3.10.10/lib/python3.10/site-packages/distlib/version.py", line 267, in parse
   result = _normalized_key(s)
 File "/tmp/bla/.direnv/python-3.10.10/lib/python3.10/site-packages/distlib/version.py", line 188, in _pep_440_key
   raise UnsupportedVersionError('Not a valid version: %s' % s)
distlib.version.UnsupportedVersionError: Not a valid version: 0.8.1dev

Expected behavior

$ python -c 'import distlib.version; print(distlib.version.NormalizedMatcher("mypackage<0.8.1dev"))'
mypackage<0.8.1.dev0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions