Skip to content

Commit

Permalink
Merge pull request #127 from finswimmer/drop-legacy-version
Browse files Browse the repository at this point in the history
fix: catch `InvalidVersion` instead of handling `LegacyVersion`
  • Loading branch information
oz123 committed Feb 5, 2023
2 parents 374e1d3 + e9ff279 commit d901f21
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ package_data =
install_requires =
attrs
cached-property
packaging
packaging>=22.0

[options.packages.find]
where = src
Expand Down
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 d901f21

Please sign in to comment.