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

fix: catch InvalidVersion instead of handling LegacyVersion #127

Merged
merged 2 commits into from
Feb 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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