Skip to content

Commit

Permalink
Merge pull request pypa#9424 from jdufresne/typing-no-guard
Browse files Browse the repository at this point in the history
Remove typing.TYPE_CHECKING guards
  • Loading branch information
pradyunsg authored Feb 20, 2021
2 parents b588c58 + 0945809 commit 25114e1
Show file tree
Hide file tree
Showing 129 changed files with 539 additions and 1,034 deletions.
8 changes: 2 additions & 6 deletions docs/docs_feedback_sphinxext.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
from __future__ import annotations

from itertools import chain
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Dict, List, Union

from sphinx.application import Sphinx
from typing import Dict, List, Union

from sphinx.application import Sphinx

DEFAULT_DOC_LINES_THRESHOLD = 250
RST_INDENT = 4
Expand Down
Empty file.
6 changes: 1 addition & 5 deletions src/pip/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import List, Optional

from typing import List, Optional

__version__ = "21.1.dev0"

Expand Down
5 changes: 1 addition & 4 deletions src/pip/_internal/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from typing import TYPE_CHECKING
from typing import List, Optional

import pip._internal.utils.inject_securetransport # noqa

if TYPE_CHECKING:
from typing import List, Optional


def main(args=None):
# type: (Optional[List[str]]) -> int
Expand Down
6 changes: 2 additions & 4 deletions src/pip/_internal/build_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from collections import OrderedDict
from distutils.sysconfig import get_python_lib
from sysconfig import get_paths
from typing import TYPE_CHECKING
from types import TracebackType
from typing import TYPE_CHECKING, Iterable, List, Optional, Set, Tuple, Type

from pip._vendor.pkg_resources import Requirement, VersionConflict, WorkingSet

Expand All @@ -18,9 +19,6 @@
from pip._internal.utils.temp_dir import TempDirectory, tempdir_kinds

if TYPE_CHECKING:
from types import TracebackType
from typing import Iterable, List, Optional, Set, Tuple, Type

from pip._internal.index.package_finder import PackageFinder

logger = logging.getLogger(__name__)
Expand Down
12 changes: 3 additions & 9 deletions src/pip/_internal/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,18 @@
import json
import logging
import os
from typing import TYPE_CHECKING
from typing import Any, Dict, List, Optional, Set

from pip._vendor.packaging.tags import interpreter_name, interpreter_version
from pip._vendor.packaging.tags import Tag, interpreter_name, interpreter_version
from pip._vendor.packaging.utils import canonicalize_name

from pip._internal.exceptions import InvalidWheelFilename
from pip._internal.models.format_control import FormatControl
from pip._internal.models.link import Link
from pip._internal.models.wheel import Wheel
from pip._internal.utils.temp_dir import TempDirectory, tempdir_kinds
from pip._internal.utils.urls import path_to_url

if TYPE_CHECKING:
from typing import Any, Dict, List, Optional, Set

from pip._vendor.packaging.tags import Tag

from pip._internal.models.format_control import FormatControl

logger = logging.getLogger(__name__)


Expand Down
5 changes: 1 addition & 4 deletions src/pip/_internal/cli/autocompletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
import os
import sys
from itertools import chain
from typing import TYPE_CHECKING
from typing import Any, Iterable, List, Optional

from pip._internal.cli.main_parser import create_main_parser
from pip._internal.commands import commands_dict, create_command
from pip._internal.utils.misc import get_installed_distributions

if TYPE_CHECKING:
from typing import Any, Iterable, List, Optional


def autocomplete():
# type: () -> None
Expand Down
12 changes: 3 additions & 9 deletions src/pip/_internal/cli/base_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import os
import sys
import traceback
from typing import TYPE_CHECKING
from optparse import Values
from typing import Any, List, Optional, Tuple

from pip._internal.cli import cmdoptions
from pip._internal.cli.command_context import CommandContextMixIn
Expand All @@ -29,17 +30,10 @@
from pip._internal.utils.filesystem import check_path_owner
from pip._internal.utils.logging import BrokenStdoutLoggingError, setup_logging
from pip._internal.utils.misc import get_prog, normalize_path
from pip._internal.utils.temp_dir import TempDirectoryTypeRegistry as TempDirRegistry
from pip._internal.utils.temp_dir import global_tempdir_manager, tempdir_registry
from pip._internal.utils.virtualenv import running_under_virtualenv

if TYPE_CHECKING:
from optparse import Values
from typing import Any, List, Optional, Tuple

from pip._internal.utils.temp_dir import (
TempDirectoryTypeRegistry as TempDirRegistry,
)

__all__ = ['Command']

logger = logging.getLogger(__name__)
Expand Down
11 changes: 3 additions & 8 deletions src/pip/_internal/cli/cmdoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
import textwrap
import warnings
from functools import partial
from optparse import SUPPRESS_HELP, Option, OptionGroup
from optparse import SUPPRESS_HELP, Option, OptionGroup, OptionParser, Values
from textwrap import dedent
from typing import TYPE_CHECKING
from typing import Any, Callable, Dict, Optional, Tuple

from pip._vendor.packaging.utils import canonicalize_name

from pip._internal.cli.parser import ConfigOptionParser
from pip._internal.cli.progress_bars import BAR_TYPES
from pip._internal.exceptions import CommandError
from pip._internal.locations import USER_CACHE_DIR, get_src_prefix
Expand All @@ -29,12 +30,6 @@
from pip._internal.utils.hashes import STRONG_HASHES
from pip._internal.utils.misc import strtobool

if TYPE_CHECKING:
from optparse import OptionParser, Values
from typing import Any, Callable, Dict, Optional, Tuple

from pip._internal.cli.parser import ConfigOptionParser


def raise_option_error(parser, option, msg):
# type: (OptionParser, Option, str) -> None
Expand Down
7 changes: 2 additions & 5 deletions src/pip/_internal/cli/command_context.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from contextlib import ExitStack, contextmanager
from typing import TYPE_CHECKING
from typing import ContextManager, Iterator, TypeVar

if TYPE_CHECKING:
from typing import ContextManager, Iterator, TypeVar

_T = TypeVar('_T', covariant=True)
_T = TypeVar('_T', covariant=True)


class CommandContextMixIn:
Expand Down
5 changes: 1 addition & 4 deletions src/pip/_internal/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@
import logging
import os
import sys
from typing import TYPE_CHECKING
from typing import List, Optional

from pip._internal.cli.autocompletion import autocomplete
from pip._internal.cli.main_parser import parse_command
from pip._internal.commands import create_command
from pip._internal.exceptions import PipError
from pip._internal.utils import deprecation

if TYPE_CHECKING:
from typing import List, Optional

logger = logging.getLogger(__name__)


Expand Down
6 changes: 1 addition & 5 deletions src/pip/_internal/cli/main_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@

import os
import sys
from typing import TYPE_CHECKING
from typing import List, Tuple

from pip._internal.cli import cmdoptions
from pip._internal.cli.parser import ConfigOptionParser, UpdatingDefaultsHelpFormatter
from pip._internal.commands import commands_dict, get_similar_commands
from pip._internal.exceptions import CommandError
from pip._internal.utils.misc import get_pip_version, get_prog

if TYPE_CHECKING:
from typing import List, Tuple


__all__ = ["create_main_parser", "parse_command"]


Expand Down
5 changes: 1 addition & 4 deletions src/pip/_internal/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@
import sys
import textwrap
from contextlib import suppress
from typing import TYPE_CHECKING
from typing import Any

from pip._internal.cli.status_codes import UNKNOWN_ERROR
from pip._internal.configuration import Configuration, ConfigurationError
from pip._internal.utils.misc import redact_auth_from_url, strtobool

if TYPE_CHECKING:
from typing import Any

logger = logging.getLogger(__name__)


Expand Down
5 changes: 1 addition & 4 deletions src/pip/_internal/cli/progress_bars.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import itertools
import sys
from signal import SIGINT, default_int_handler, signal
from typing import TYPE_CHECKING
from typing import Any, Dict, List

from pip._vendor.progress.bar import Bar, FillingCirclesBar, IncrementalBar
from pip._vendor.progress.spinner import Spinner
Expand All @@ -10,9 +10,6 @@
from pip._internal.utils.logging import get_indentation
from pip._internal.utils.misc import format_size

if TYPE_CHECKING:
from typing import Any, Dict, List

try:
from pip._vendor import colorama
# Lots of different errors can come from this, including SystemError and
Expand Down
26 changes: 12 additions & 14 deletions src/pip/_internal/cli/req_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@
import logging
import os
from functools import partial
from typing import TYPE_CHECKING
from optparse import Values
from typing import Any, List, Optional, Tuple

from pip._internal.cache import WheelCache
from pip._internal.cli import cmdoptions
from pip._internal.cli.base_command import Command
from pip._internal.cli.command_context import CommandContextMixIn
from pip._internal.exceptions import CommandError, PreviousBuildDirError
from pip._internal.index.collector import LinkCollector
from pip._internal.index.package_finder import PackageFinder
from pip._internal.models.selection_prefs import SelectionPreferences
from pip._internal.models.target_python import TargetPython
from pip._internal.network.session import PipSession
from pip._internal.operations.prepare import RequirementPreparer
from pip._internal.req.constructors import (
Expand All @@ -26,20 +29,15 @@
install_req_from_req_string,
)
from pip._internal.req.req_file import parse_requirements
from pip._internal.req.req_install import InstallRequirement
from pip._internal.req.req_tracker import RequirementTracker
from pip._internal.resolution.base import BaseResolver
from pip._internal.self_outdated_check import pip_self_version_check
from pip._internal.utils.temp_dir import tempdir_kinds

if TYPE_CHECKING:
from optparse import Values
from typing import Any, List, Optional, Tuple

from pip._internal.cache import WheelCache
from pip._internal.models.target_python import TargetPython
from pip._internal.req.req_install import InstallRequirement
from pip._internal.req.req_tracker import RequirementTracker
from pip._internal.resolution.base import BaseResolver
from pip._internal.utils.temp_dir import TempDirectory, TempDirectoryTypeRegistry

from pip._internal.utils.temp_dir import (
TempDirectory,
TempDirectoryTypeRegistry,
tempdir_kinds,
)

logger = logging.getLogger(__name__)

Expand Down
5 changes: 1 addition & 4 deletions src/pip/_internal/cli/spinners.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
import logging
import sys
import time
from typing import TYPE_CHECKING
from typing import IO, Iterator

from pip._vendor.progress import HIDE_CURSOR, SHOW_CURSOR

from pip._internal.utils.compat import WINDOWS
from pip._internal.utils.logging import get_indentation

if TYPE_CHECKING:
from typing import IO, Iterator

logger = logging.getLogger(__name__)


Expand Down
8 changes: 2 additions & 6 deletions src/pip/_internal/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@

import importlib
from collections import OrderedDict, namedtuple
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any, Optional

from pip._internal.cli.base_command import Command
from typing import Any, Optional

from pip._internal.cli.base_command import Command

CommandInfo = namedtuple('CommandInfo', 'module_path, class_name, summary')

Expand Down
8 changes: 2 additions & 6 deletions src/pip/_internal/commands/cache.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import logging
import os
import textwrap
from typing import TYPE_CHECKING
from optparse import Values
from typing import Any, List

import pip._internal.utils.filesystem as filesystem
from pip._internal.cli.base_command import Command
from pip._internal.cli.status_codes import ERROR, SUCCESS
from pip._internal.exceptions import CommandError, PipError

if TYPE_CHECKING:
from optparse import Values
from typing import Any, List


logger = logging.getLogger(__name__)


Expand Down
7 changes: 2 additions & 5 deletions src/pip/_internal/commands/check.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
from typing import TYPE_CHECKING
from optparse import Values
from typing import Any, List

from pip._internal.cli.base_command import Command
from pip._internal.cli.status_codes import ERROR, SUCCESS
Expand All @@ -11,10 +12,6 @@

logger = logging.getLogger(__name__)

if TYPE_CHECKING:
from optparse import Values
from typing import Any, List


class CheckCommand(Command):
"""Verify installed packages have compatible dependencies."""
Expand Down
7 changes: 2 additions & 5 deletions src/pip/_internal/commands/completion.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import sys
import textwrap
from typing import TYPE_CHECKING
from optparse import Values
from typing import List

from pip._internal.cli.base_command import Command
from pip._internal.cli.status_codes import SUCCESS
from pip._internal.utils.misc import get_prog

if TYPE_CHECKING:
from optparse import Values
from typing import List

BASE_COMPLETION = """
# pip {shell} completion start{script}# pip {shell} completion end
"""
Expand Down
Loading

0 comments on commit 25114e1

Please sign in to comment.