diff --git a/news/BF3EC962-957A-4DB8-A849-2E7179F875A9.trivial b/news/BF3EC962-957A-4DB8-A849-2E7179F875A9.trivial new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/pip/_internal/commands/hash.py b/src/pip/_internal/commands/hash.py index f26686156ee..aab4a3dc2fe 100644 --- a/src/pip/_internal/commands/hash.py +++ b/src/pip/_internal/commands/hash.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 hashlib @@ -8,9 +5,14 @@ import sys from pip._internal.cli.base_command import Command -from pip._internal.cli.status_codes import ERROR +from pip._internal.cli.status_codes import ERROR, SUCCESS from pip._internal.utils.hashes import FAVORITE_HASH, STRONG_HASHES from pip._internal.utils.misc import read_chunks, write_output +from pip._internal.utils.typing import MYPY_CHECK_RUNNING + +if MYPY_CHECK_RUNNING: + from optparse import Values + from typing import Any, List logger = logging.getLogger(__name__) @@ -27,6 +29,7 @@ class HashCommand(Command): ignore_require_venv = True def __init__(self, *args, **kw): + # type: (*Any, **Any) -> None super(HashCommand, self).__init__(*args, **kw) self.cmd_opts.add_option( '-a', '--algorithm', @@ -39,6 +42,7 @@ def __init__(self, *args, **kw): self.parser.insert_option_group(0, self.cmd_opts) def run(self, options, args): + # type: (Values, List[str]) -> int if not args: self.parser.print_usage(sys.stderr) return ERROR @@ -47,9 +51,11 @@ def run(self, options, args): for path in args: write_output('%s:\n--hash=%s:%s', path, algorithm, _hash_of_file(path, algorithm)) + return SUCCESS def _hash_of_file(path, algorithm): + # type: (str, str) -> str """Return the hash digest of a file.""" with open(path, 'rb') as archive: hash = hashlib.new(algorithm) diff --git a/src/pip/_internal/commands/show.py b/src/pip/_internal/commands/show.py index a61294ba7bb..8d9fa13fd91 100644 --- a/src/pip/_internal/commands/show.py +++ b/src/pip/_internal/commands/show.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 logging @@ -13,6 +10,11 @@ from pip._internal.cli.base_command import Command from pip._internal.cli.status_codes import ERROR, SUCCESS from pip._internal.utils.misc import write_output +from pip._internal.utils.typing import MYPY_CHECK_RUNNING + +if MYPY_CHECK_RUNNING: + from optparse import Values + from typing import Any, List, Dict, Iterator logger = logging.getLogger(__name__) @@ -29,6 +31,7 @@ class ShowCommand(Command): ignore_require_venv = True def __init__(self, *args, **kw): + # type: (*Any, **Any) -> None super(ShowCommand, self).__init__(*args, **kw) self.cmd_opts.add_option( '-f', '--files', @@ -40,6 +43,7 @@ def __init__(self, *args, **kw): self.parser.insert_option_group(0, self.cmd_opts) def run(self, options, args): + # type: (Values, List[str]) -> int if not args: logger.warning('ERROR: Please provide a package name or names.') return ERROR @@ -53,6 +57,7 @@ def run(self, options, args): def search_packages_info(query): + # type: (List[str]) -> Iterator[Dict[str, str]] """ Gather details from installed distributions. Print distribution name, version, location, and installed files. Installed files requires a @@ -71,6 +76,7 @@ def search_packages_info(query): logger.warning('Package(s) not found: %s', ', '.join(missing)) def get_requiring_packages(package_name): + # type: (str) -> List[str] canonical_name = canonicalize_name(package_name) return [ pkg.project_name for pkg in pkg_resources.working_set @@ -88,7 +94,7 @@ def get_requiring_packages(package_name): 'required_by': get_requiring_packages(dist.project_name) } file_list = None - metadata = None + metadata = '' if isinstance(dist, pkg_resources.DistInfoDistribution): # RECORDs should be part of .dist-info metadatas if dist.has_metadata('RECORD'): @@ -141,6 +147,7 @@ def get_requiring_packages(package_name): def print_results(distributions, list_files=False, verbose=False): + # type: (Iterator[Dict[str, str]], bool, bool) -> bool """ Print the information from installed distributions found. """ diff --git a/src/pip/_internal/commands/wheel.py b/src/pip/_internal/commands/wheel.py index 48f3bfa29ca..f028d681f7b 100644 --- a/src/pip/_internal/commands/wheel.py +++ b/src/pip/_internal/commands/wheel.py @@ -1,8 +1,5 @@ # -*- coding: utf-8 -*- -# The following comment should be removed at some point in the future. -# mypy: disallow-untyped-defs=False - from __future__ import absolute_import import logging @@ -12,6 +9,7 @@ from pip._internal.cache import WheelCache from pip._internal.cli import cmdoptions from pip._internal.cli.req_command import RequirementCommand, with_cleanup +from pip._internal.cli.status_codes import SUCCESS from pip._internal.exceptions import CommandError from pip._internal.req.req_tracker import get_requirement_tracker from pip._internal.utils.misc import ensure_dir, normalize_path @@ -50,6 +48,7 @@ class WheelCommand(RequirementCommand): %prog [options] ...""" def __init__(self, *args, **kw): + # type: (*Any, **Any) -> None super(WheelCommand, self).__init__(*args, **kw) cmd_opts = self.cmd_opts @@ -112,7 +111,7 @@ def __init__(self, *args, **kw): @with_cleanup def run(self, options, args): - # type: (Values, List[Any]) -> None + # type: (Values, List[str]) -> int cmdoptions.check_install_build_global(options) session = self.get_default_session(options) @@ -188,3 +187,5 @@ def run(self, options, args): raise CommandError( "Failed to build one or more wheels" ) + + return SUCCESS