diff --git a/news/9CD0A87D-0ACD-418E-8C02-4560A99FEB71.trivial b/news/9CD0A87D-0ACD-418E-8C02-4560A99FEB71.trivial new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/pip/_internal/commands/help.py b/src/pip/_internal/commands/help.py index c17d7a457c4..82075c41565 100644 --- a/src/pip/_internal/commands/help.py +++ b/src/pip/_internal/commands/help.py @@ -1,11 +1,13 @@ -# The following comment should be removed at some point in the future. -# mypy: disallow-untyped-defs=False - from __future__ import absolute_import from pip._internal.cli.base_command import Command from pip._internal.cli.status_codes import SUCCESS from pip._internal.exceptions import CommandError +from pip._internal.utils.typing import MYPY_CHECK_RUNNING + +if MYPY_CHECK_RUNNING: + from typing import List, Any + from optparse import Values class HelpCommand(Command): @@ -16,6 +18,8 @@ class HelpCommand(Command): ignore_require_venv = True def run(self, options, args): + # type: (Values, List[Any]) -> int + from pip._internal.commands import ( commands_dict, create_command, get_similar_commands, ) diff --git a/src/pip/_internal/commands/list.py b/src/pip/_internal/commands/list.py index 109ec5c664e..7b6c99936d1 100644 --- a/src/pip/_internal/commands/list.py +++ b/src/pip/_internal/commands/list.py @@ -1,6 +1,3 @@ -# The following comment should be removed at some point in the future. -# mypy: disallow-untyped-defs=False - from __future__ import absolute_import import json @@ -21,6 +18,14 @@ write_output, ) from pip._internal.utils.packaging import get_installer +from pip._internal.utils.typing import MYPY_CHECK_RUNNING + +if MYPY_CHECK_RUNNING: + from optparse import Values + from typing import Any, List, Set, Tuple, Dict + + from pip._internal.network.session import PipSession + from pip._vendor.pkg_resources import Distribution logger = logging.getLogger(__name__) @@ -36,7 +41,9 @@ class ListCommand(IndexGroupCommand): %prog [options]""" def __init__(self, *args, **kw): - super(ListCommand, self).__init__(*args, **kw) + # type: (List[Any], Dict[Any, Any]) -> None + # https://github.com/python/mypy/issues/4335 + super(ListCommand, self).__init__(*args, **kw) # type: ignore cmd_opts = self.cmd_opts @@ -116,6 +123,7 @@ def __init__(self, *args, **kw): self.parser.insert_option_group(0, cmd_opts) def _build_package_finder(self, options, session): + # type: (Values, PipSession) -> PackageFinder """ Create a package finder appropriate to this list command. """ @@ -133,6 +141,8 @@ def _build_package_finder(self, options, session): ) def run(self, options, args): + # type: (Values, List[Any]) -> None + if options.outdated and options.uptodate: raise CommandError( "Options --outdated and --uptodate cannot be combined.") @@ -162,24 +172,29 @@ def run(self, options, args): self.output_package_listing(packages, options) def get_outdated(self, packages, options): + # type: (List[Distribution], Values) -> List[Distribution] + return [ dist for dist in self.iter_packages_latest_infos(packages, options) if dist.latest_version > dist.parsed_version ] def get_uptodate(self, packages, options): + # type: (List[Distribution], Values) -> List[Distribution] return [ dist for dist in self.iter_packages_latest_infos(packages, options) if dist.latest_version == dist.parsed_version ] def get_not_required(self, packages, options): - dep_keys = set() + # type: (List[Distribution], Values) -> List[Distribution] + dep_keys = set() # type: Set[Distribution] for dist in packages: dep_keys.update(requirement.key for requirement in dist.requires()) - return {pkg for pkg in packages if pkg.key not in dep_keys} + return [pkg for pkg in packages if pkg.key not in dep_keys] def iter_packages_latest_infos(self, packages, options): + # type: (List[Distribution], Values) -> Distribution with self._build_session(options) as session: finder = self._build_package_finder(options, session) @@ -209,6 +224,7 @@ def iter_packages_latest_infos(self, packages, options): yield dist def output_package_listing(self, packages, options): + # type: (List[Distribution], Values) -> None packages = sorted( packages, key=lambda dist: dist.project_name.lower(), @@ -227,6 +243,7 @@ def output_package_listing(self, packages, options): write_output(format_for_json(packages, options)) def output_package_listing_columns(self, data, header): + # type: (List[List[Any]], List[str]) -> None # insert the header first: we need to know the size of column names if len(data) > 0: data.insert(0, header) @@ -242,6 +259,7 @@ def output_package_listing_columns(self, data, header): def format_for_columns(pkgs, options): + # type: (List[Distribution], Values) -> Tuple[List[List[Any]], List[str]] """ Convert the package data into something usable by output_package_listing_columns. @@ -279,6 +297,7 @@ def format_for_columns(pkgs, options): def format_for_json(packages, options): + # type: (List[Distribution], Values) -> str data = [] for dist in packages: info = { diff --git a/src/pip/_internal/commands/uninstall.py b/src/pip/_internal/commands/uninstall.py index 5db4fb46721..b07272fc7ff 100644 --- a/src/pip/_internal/commands/uninstall.py +++ b/src/pip/_internal/commands/uninstall.py @@ -1,6 +1,3 @@ -# The following comment should be removed at some point in the future. -# mypy: disallow-untyped-defs=False - from __future__ import absolute_import from pip._vendor.packaging.utils import canonicalize_name @@ -14,6 +11,11 @@ install_req_from_parsed_requirement, ) from pip._internal.utils.misc import protect_pip_from_modification_on_windows +from pip._internal.utils.typing import MYPY_CHECK_RUNNING + +if MYPY_CHECK_RUNNING: + from optparse import Values + from typing import Any, List, Dict class UninstallCommand(Command, SessionCommandMixin): @@ -32,7 +34,9 @@ class UninstallCommand(Command, SessionCommandMixin): %prog [options] -r ...""" def __init__(self, *args, **kw): - super(UninstallCommand, self).__init__(*args, **kw) + # type: (List[Any], Dict[Any, Any]) -> None + # https://github.com/python/mypy/issues/4335 + super(UninstallCommand, self).__init__(*args, **kw) # type: ignore self.cmd_opts.add_option( '-r', '--requirement', dest='requirements', @@ -51,6 +55,8 @@ def __init__(self, *args, **kw): self.parser.insert_option_group(0, self.cmd_opts) def run(self, options, args): + # type: (Values, List[Any]) -> None + session = self.get_default_session(options) reqs_to_uninstall = {}