Skip to content

Commit

Permalink
Simplify the handling of "typing.cast"
Browse files Browse the repository at this point in the history
  • Loading branch information
pradyunsg committed Jul 30, 2019
1 parent 80b82b5 commit 2a5c23b
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/pip/_internal/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,18 @@
if MYPY_CHECK_RUNNING:
from typing import (
Any, AnyStr, Container, Iterable, List, Mapping, Match, Optional, Text,
Union,
Tuple, Union, cast,
)
from pip._vendor.pkg_resources import Distribution
from pip._internal.models.link import Link
from pip._internal.utils.ui import SpinnerInterface

try:
from typing import cast, Tuple
VersionInfo = Tuple[int, int, int]
except ImportError:
# typing's cast() isn't supported in code comments, so we need to
# define a dummy, no-op version.
def cast(typ, val): # type: ignore
return val
VersionInfo = None # type: ignore
else:
# typing's cast() is needed at runtime, but we don't want to import typing.
# Thus, we use a dummy no-op version, which we tell mypy to ignore.
def cast(type_, value): # type: ignore
return value


__all__ = ['rmtree', 'display_path', 'backup_dir',
Expand Down Expand Up @@ -140,7 +137,7 @@ def normalize_version_info(py_version_info):
elif len(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):
Expand Down

0 comments on commit 2a5c23b

Please sign in to comment.