Skip to content

Commit

Permalink
fix: catch InvalidVersion instead of handling LegacyVersion
Browse files Browse the repository at this point in the history
LegacyVersion was removed from packaging in version 22.0
  • Loading branch information
finswimmer committed Dec 21, 2022
1 parent 374e1d3 commit a8a74b0
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/pythonfinder/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from threading import Timer

import attr
from packaging.version import LegacyVersion, Version
from packaging.version import Version, InvalidVersion

from .compat import Path, TimeoutError, lru_cache # noqa
from .environment import MYPY_RUNNING, PYENV_ROOT, SUBPROCESS_TIMEOUT
Expand Down Expand Up @@ -130,12 +130,15 @@ def parse_python_version(version_str):
is_devrelease = True if version_dict.get("dev") else False
if patch:
patch = int(patch)
version = None # type: Optional[Union[Version, LegacyVersion]]

version = None # type: Optional[Version]

try:
version = parse_version(version_str)
except TypeError:
except (TypeError, InvalidVersion):
version = None
if isinstance(version, LegacyVersion) or version is None:

if version is None:
v_dict = version_dict.copy()
pre = ""
if v_dict.get("prerel") and v_dict.get("prerelversion"):
Expand Down

0 comments on commit a8a74b0

Please sign in to comment.