Skip to content

Commit c8e4afa

Browse files
authored
Merge pull request #7977 from deveshks/add-mypy-annotations-commands
Added type annotations to pip._internal.commands.check
2 parents ea1295b + c2fdf4a commit c8e4afa

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

news/1C96C81F-4A3E-42AD-9562-7BB7EB0A7EF9.trivial

Whitespace-only changes.

src/pip/_internal/commands/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
# The following comment should be removed at some point in the future.
66
# mypy: disallow-untyped-defs=False
7+
# There is currently a bug in python/typeshed mentioned at
8+
# https://github.com/python/typeshed/issues/3906 which causes the
9+
# return type of difflib.get_close_matches to be reported
10+
# as List[Sequence[str]] whereas it should have been List[str]
711

812
from __future__ import absolute_import
913

src/pip/_internal/commands/check.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
# The following comment should be removed at some point in the future.
2-
# mypy: disallow-untyped-defs=False
3-
41
import logging
52

63
from pip._internal.cli.base_command import Command
4+
from pip._internal.cli.status_codes import ERROR, SUCCESS
75
from pip._internal.operations.check import (
86
check_package_set,
97
create_package_set_from_installed,
108
)
119
from pip._internal.utils.misc import write_output
10+
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
1211

1312
logger = logging.getLogger(__name__)
1413

14+
if MYPY_CHECK_RUNNING:
15+
from typing import List, Any
16+
from optparse import Values
17+
1518

1619
class CheckCommand(Command):
1720
"""Verify installed packages have compatible dependencies."""
@@ -20,6 +23,8 @@ class CheckCommand(Command):
2023
%prog [options]"""
2124

2225
def run(self, options, args):
26+
# type: (Values, List[Any]) -> int
27+
2328
package_set, parsing_probs = create_package_set_from_installed()
2429
missing, conflicting = check_package_set(package_set)
2530

@@ -40,6 +45,7 @@ def run(self, options, args):
4045
)
4146

4247
if missing or conflicting or parsing_probs:
43-
return 1
48+
return ERROR
4449
else:
4550
write_output("No broken requirements found.")
51+
return SUCCESS

0 commit comments

Comments
 (0)