Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert type hint comments into annotations #10018

Merged
merged 33 commits into from Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2d19102
Convert commentaries into annotations
DiddiLeija May 26, 2021
1753788
Create 10018.trivial.rst
DiddiLeija May 26, 2021
65b4dbc
Fix the annotations
DiddiLeija May 26, 2021
2dc2e62
Update src/pip/__init__.py
DiddiLeija May 26, 2021
0c5d9e8
Fix the annotations
DiddiLeija May 26, 2021
acfeaba
Fix the annotations on base_command.py
DiddiLeija May 26, 2021
234a9ed
Fix an annotation mistake.
DiddiLeija May 26, 2021
a049283
Fix the annotations
DiddiLeija May 26, 2021
773aa7d
Fix an annotation mistake
DiddiLeija May 27, 2021
5d405cd
Update the annotations
DiddiLeija May 27, 2021
338d1d7
Format some annotations
DiddiLeija May 27, 2021
ee5bf42
Update annotations on cmdoptions.py
DiddiLeija May 27, 2021
5079aa8
Fix the cmdoptions.py annotations
DiddiLeija May 27, 2021
423cdff
Fix the annotations length
DiddiLeija May 27, 2021
6319660
Fix the annotations length
DiddiLeija May 27, 2021
ee89922
Merge branch 'pypa:main' into annotations-fixes-1
DiddiLeija May 28, 2021
e62a77b
Fix the cmdoptions.py return values
DiddiLeija May 28, 2021
876cde6
Annotate when a function/method returns None
DiddiLeija May 28, 2021
3c9cef9
Fix the annotation length
DiddiLeija May 28, 2021
b909841
Annotate when a function/method returns nothing
DiddiLeija May 28, 2021
de0b3bd
Annotate on command_context.py
DiddiLeija May 28, 2021
0058b06
Properly annotate into main.py
DiddiLeija May 28, 2021
731f0b0
Convert commentaries into annotations
DiddiLeija May 28, 2021
2d37947
Use proper annotations
DiddiLeija May 28, 2021
1d317bb
Fix some annotations
DiddiLeija May 28, 2021
969018b
Fix some annotations
DiddiLeija May 28, 2021
d9aa531
Fix theannotation length
DiddiLeija May 28, 2021
691da80
Update src/pip/_internal/cli/base_command.py
DiddiLeija May 28, 2021
f311646
Merge branch 'pypa:main' into annotations-fixes-1
DiddiLeija May 31, 2021
0f0a1ac
Merge branch 'pypa:main' into annotations-fixes-1
DiddiLeija Jun 2, 2021
8159398
Merge branch 'pypa:main' into annotations-fixes-1
DiddiLeija Jun 3, 2021
eba22d6
Merge branch 'pypa:main' into annotations-fixes-1
DiddiLeija Jun 4, 2021
b026568
Merge branch 'pypa:main' into annotations-fixes-1
DiddiLeija Jun 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions news/10018.trivial.rst
@@ -0,0 +1 @@
Use annotations from the ``typing`` module on some functions.
3 changes: 1 addition & 2 deletions src/pip/__init__.py
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
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
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
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