mirror of https://github.com/pypa/pip
Simplify the handling of "typing.cast"
This commit is contained in:
parent
cb00488ca6
commit
4601a8d83f
|
@ -48,21 +48,18 @@ else:
|
||||||
if MYPY_CHECK_RUNNING:
|
if MYPY_CHECK_RUNNING:
|
||||||
from typing import (
|
from typing import (
|
||||||
Any, AnyStr, Container, Iterable, List, Mapping, Match, Optional, Text,
|
Any, AnyStr, Container, Iterable, List, Mapping, Match, Optional, Text,
|
||||||
Union,
|
Tuple, Union, cast,
|
||||||
)
|
)
|
||||||
from pip._vendor.pkg_resources import Distribution
|
from pip._vendor.pkg_resources import Distribution
|
||||||
from pip._internal.models.link import Link
|
from pip._internal.models.link import Link
|
||||||
from pip._internal.utils.ui import SpinnerInterface
|
from pip._internal.utils.ui import SpinnerInterface
|
||||||
|
|
||||||
try:
|
|
||||||
from typing import cast, Tuple
|
|
||||||
VersionInfo = Tuple[int, int, int]
|
VersionInfo = Tuple[int, int, int]
|
||||||
except ImportError:
|
else:
|
||||||
# typing's cast() isn't supported in code comments, so we need to
|
# typing's cast() is needed at runtime, but we don't want to import typing.
|
||||||
# define a dummy, no-op version.
|
# Thus, we use a dummy no-op version, which we tell mypy to ignore.
|
||||||
def cast(typ, val):
|
def cast(type_, value): # type: ignore
|
||||||
return val
|
return value
|
||||||
VersionInfo = None
|
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['rmtree', 'display_path', 'backup_dir',
|
__all__ = ['rmtree', 'display_path', 'backup_dir',
|
||||||
|
@ -135,7 +132,7 @@ def normalize_version_info(py_version_info):
|
||||||
elif len(py_version_info) > 3:
|
elif len(py_version_info) > 3:
|
||||||
py_version_info = py_version_info[:3]
|
py_version_info = py_version_info[:3]
|
||||||
|
|
||||||
return cast(VersionInfo, py_version_info)
|
return cast('VersionInfo', py_version_info)
|
||||||
|
|
||||||
|
|
||||||
def ensure_dir(path):
|
def ensure_dir(path):
|
||||||
|
|
Loading…
Reference in New Issue