Skip to content

Commit

Permalink
Convert type hint comments into annotations
Browse files Browse the repository at this point in the history
Co-authored-by: Pradyun Gedam <pradyunsg@gmail.com>
Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
  • Loading branch information
3 people authored Jun 7, 2021
1 parent 0170e37 commit 1e016d2
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 132 deletions.
1 change: 1 addition & 0 deletions news/10018.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use annotations from the ``typing`` module on some functions.
3 changes: 1 addition & 2 deletions src/pip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
__version__ = "21.2.dev0"


def main(args=None):
# type: (Optional[List[str]]) -> int
def main(args: Optional[List[str]] = None) -> int:
"""This is an internal API only meant for use by pip's own console scripts.
For additional details, see https://github.com/pypa/pip/issues/7498.
Expand Down
3 changes: 1 addition & 2 deletions src/pip/_internal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import pip._internal.utils.inject_securetransport # noqa


def main(args=None):
# type: (Optional[List[str]]) -> int
def main(args: (Optional[List[str]]) = None) -> int:
"""This is preserved for old console scripts that may still be referencing
it.
Expand Down
11 changes: 5 additions & 6 deletions src/pip/_internal/cli/autocompletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
from pip._internal.utils.misc import get_installed_distributions


def autocomplete():
# type: () -> None
def autocomplete() -> None:
"""Entry Point for completion of main and subcommand options."""
# Don't complete if user hasn't sourced bash_completion file.
if "PIP_AUTO_COMPLETE" not in os.environ:
Expand Down Expand Up @@ -107,8 +106,9 @@ def autocomplete():
sys.exit(1)


def get_path_completion_type(cwords, cword, opts):
# type: (List[str], int, Iterable[Any]) -> Optional[str]
def get_path_completion_type(
cwords: List[str], cword: int, opts: Iterable[Any]
) -> Optional[str]:
"""Get the type of path completion (``file``, ``dir``, ``path`` or None)
:param cwords: same as the environmental variable ``COMP_WORDS``
Expand All @@ -130,8 +130,7 @@ def get_path_completion_type(cwords, cword, opts):
return None


def auto_complete_paths(current, completion_type):
# type: (str, str) -> Iterable[str]
def auto_complete_paths(current: str, completion_type: str) -> Iterable[str]:
"""If ``completion_type`` is ``file`` or ``path``, list all regular files
and directories starting with ``current``; otherwise only list directories
starting with ``current``.
Expand Down
21 changes: 7 additions & 14 deletions src/pip/_internal/cli/base_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class Command(CommandContextMixIn):
usage = None # type: str
ignore_require_venv = False # type: bool

def __init__(self, name, summary, isolated=False):
# type: (str, str, bool) -> None
def __init__(self, name: str, summary: str, isolated: bool = False) -> None:
super().__init__()

self.name = name
Expand Down Expand Up @@ -74,12 +73,10 @@ def __init__(self, name, summary, isolated=False):

self.add_options()

def add_options(self):
# type: () -> None
def add_options(self) -> None:
pass

def handle_pip_version_check(self, options):
# type: (Values) -> None
def handle_pip_version_check(self, options: Values) -> None:
"""
This is a no-op so that commands by default do not do the pip version
check.
Expand All @@ -88,25 +85,21 @@ def handle_pip_version_check(self, options):
# are present.
assert not hasattr(options, "no_index")

def run(self, options, args):
# type: (Values, List[Any]) -> int
def run(self, options: Values, args: List[Any]) -> int:
raise NotImplementedError

def parse_args(self, args):
# type: (List[str]) -> Tuple[Any, Any]
def parse_args(self, args: List[str]) -> Tuple[Any, Any]:
# factored out for testability
return self.parser.parse_args(args)

def main(self, args):
# type: (List[str]) -> int
def main(self, args: List[str]) -> int:
try:
with self.main_context():
return self._main(args)
finally:
logging.shutdown()

def _main(self, args):
# type: (List[str]) -> int
def _main(self, args: List[str]) -> int:
# We must initialize this before the tempdir manager, otherwise the
# configuration would not be accessible by the time we clean up the
# tempdir manager.
Expand Down
Loading

0 comments on commit 1e016d2

Please sign in to comment.