From c2fdf4a35bc7db0d81743e83db57122393ec4eb7 Mon Sep 17 00:00:00 2001 From: Devesh Kumar Singh Date: Sat, 4 Apr 2020 15:01:17 +0530 Subject: [PATCH] Add mypy annotations to pip._internal.commands.check --- news/1C96C81F-4A3E-42AD-9562-7BB7EB0A7EF9.trivial | 0 src/pip/_internal/commands/__init__.py | 4 ++++ src/pip/_internal/commands/check.py | 14 ++++++++++---- 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 news/1C96C81F-4A3E-42AD-9562-7BB7EB0A7EF9.trivial diff --git a/news/1C96C81F-4A3E-42AD-9562-7BB7EB0A7EF9.trivial b/news/1C96C81F-4A3E-42AD-9562-7BB7EB0A7EF9.trivial new file mode 100644 index 000000000..e69de29bb diff --git a/src/pip/_internal/commands/__init__.py b/src/pip/_internal/commands/__init__.py index 2a311f8fc..0f0b6e022 100644 --- a/src/pip/_internal/commands/__init__.py +++ b/src/pip/_internal/commands/__init__.py @@ -4,6 +4,10 @@ Package containing all pip commands # The following comment should be removed at some point in the future. # mypy: disallow-untyped-defs=False +# There is currently a bug in python/typeshed mentioned at +# https://github.com/python/typeshed/issues/3906 which causes the +# return type of difflib.get_close_matches to be reported +# as List[Sequence[str]] whereas it should have been List[str] from __future__ import absolute_import diff --git a/src/pip/_internal/commands/check.py b/src/pip/_internal/commands/check.py index 968944611..b557ca641 100644 --- a/src/pip/_internal/commands/check.py +++ b/src/pip/_internal/commands/check.py @@ -1,17 +1,20 @@ -# The following comment should be removed at some point in the future. -# mypy: disallow-untyped-defs=False - import logging from pip._internal.cli.base_command import Command +from pip._internal.cli.status_codes import ERROR, SUCCESS from pip._internal.operations.check import ( check_package_set, create_package_set_from_installed, ) from pip._internal.utils.misc import write_output +from pip._internal.utils.typing import MYPY_CHECK_RUNNING logger = logging.getLogger(__name__) +if MYPY_CHECK_RUNNING: + from typing import List, Any + from optparse import Values + class CheckCommand(Command): """Verify installed packages have compatible dependencies.""" @@ -20,6 +23,8 @@ class CheckCommand(Command): %prog [options]""" def run(self, options, args): + # type: (Values, List[Any]) -> int + package_set, parsing_probs = create_package_set_from_installed() missing, conflicting = check_package_set(package_set) @@ -40,6 +45,7 @@ class CheckCommand(Command): ) if missing or conflicting or parsing_probs: - return 1 + return ERROR else: write_output("No broken requirements found.") + return SUCCESS