diff --git a/src/pip/_internal/utils/filesystem.py b/src/pip/_internal/utils/filesystem.py index bedd66295..bce2058bc 100644 --- a/src/pip/_internal/utils/filesystem.py +++ b/src/pip/_internal/utils/filesystem.py @@ -13,8 +13,7 @@ from pip._vendor.retrying import retry # type: ignore from pip._vendor.six import PY2 from pip._internal.utils.compat import get_path_uid -from pip._internal.utils.misc import cast -from pip._internal.utils.typing import MYPY_CHECK_RUNNING +from pip._internal.utils.typing import MYPY_CHECK_RUNNING, cast if MYPY_CHECK_RUNNING: from typing import BinaryIO, Iterator diff --git a/src/pip/_internal/utils/misc.py b/src/pip/_internal/utils/misc.py index b84826350..3e9c2c44e 100644 --- a/src/pip/_internal/utils/misc.py +++ b/src/pip/_internal/utils/misc.py @@ -39,7 +39,7 @@ from pip._internal.utils.compat import ( str_to_display, ) from pip._internal.utils.marker_files import write_delete_marker_file -from pip._internal.utils.typing import MYPY_CHECK_RUNNING +from pip._internal.utils.typing import MYPY_CHECK_RUNNING, cast from pip._internal.utils.virtualenv import ( running_under_virtualenv, virtualenv_no_global, @@ -53,16 +53,11 @@ else: if MYPY_CHECK_RUNNING: from typing import ( Any, AnyStr, Container, Iterable, List, Optional, Text, - Tuple, Union, cast, + Tuple, Union, ) from pip._vendor.pkg_resources import Distribution VersionInfo = Tuple[int, int, int] -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', diff --git a/src/pip/_internal/utils/typing.py b/src/pip/_internal/utils/typing.py index 10170ce29..8505a29b1 100644 --- a/src/pip/_internal/utils/typing.py +++ b/src/pip/_internal/utils/typing.py @@ -27,3 +27,12 @@ Ref: https://github.com/python/mypy/issues/3216 """ MYPY_CHECK_RUNNING = False + + +if MYPY_CHECK_RUNNING: + from typing import cast +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