Skip to content

Commit

Permalink
Merge pull request #5930 from cytolentino/basecommand-typing
Browse files Browse the repository at this point in the history
Add mypy annotations to base_command.py
  • Loading branch information
pradyunsg committed Oct 30, 2018
2 parents afe98f3 + 12a2334 commit 35701ea
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
Empty file.
37 changes: 31 additions & 6 deletions src/pip/_internal/cli/base_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
from pip._internal.utils.typing import MYPY_CHECK_RUNNING

if MYPY_CHECK_RUNNING:
from typing import Optional # noqa: F401
from typing import Optional, List, Union, Tuple, Any # noqa: F401
from optparse import Values # noqa: F401
from pip._internal.cache import WheelCache # noqa: F401
from pip._internal.req.req_set import RequirementSet # noqa: F401

__all__ = ['Command']

Expand All @@ -46,6 +49,7 @@ class Command(object):
ignore_require_venv = False # type: bool

def __init__(self, isolated=False):
# type: (bool) -> None
parser_kw = {
'usage': self.usage,
'prog': '%s %s' % (get_prog(), self.name),
Expand All @@ -69,7 +73,12 @@ def __init__(self, isolated=False):
)
self.parser.add_option_group(gen_opts)

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

def _build_session(self, options, retries=None, timeout=None):
# type: (Values, Optional[int], Optional[int]) -> PipSession
session = PipSession(
cache=(
normalize_path(os.path.join(options.cache_dir, "http"))
Expand Down Expand Up @@ -106,10 +115,12 @@ def _build_session(self, options, retries=None, timeout=None):
return session

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

def main(self, args):
# type: (List[str]) -> int
options, args = self.parse_args(args)

# Set verbosity so that it can be used elsewhere.
Expand Down Expand Up @@ -195,8 +206,15 @@ def main(self, args):
class RequirementCommand(Command):

@staticmethod
def populate_requirement_set(requirement_set, args, options, finder,
session, name, wheel_cache):
def populate_requirement_set(requirement_set, # type: RequirementSet
args, # type: List[str]
options, # type: Values
finder, # type: PackageFinder
session, # type: PipSession
name, # type: str
wheel_cache # type: Optional[WheelCache]
):
# type: (...) -> None
"""
Marshal cmd line args into a requirement set.
"""
Expand Down Expand Up @@ -251,9 +269,16 @@ def populate_requirement_set(requirement_set, args, options, finder,
'You must give at least one requirement to %(name)s '
'(see "pip help %(name)s")' % opts)

def _build_package_finder(self, options, session,
platform=None, python_versions=None,
abi=None, implementation=None):
def _build_package_finder(
self,
options, # type: Values
session, # type: PipSession
platform=None, # type: Optional[str]
python_versions=None, # type: Optional[List[str]]
abi=None, # type: Optional[str]
implementation=None # type: Optional[str]
):
# type: (...) -> PackageFinder
"""
Create a package finder appropriate to this requirement command.
"""
Expand Down
6 changes: 5 additions & 1 deletion src/pip/_internal/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@
)
from pip._internal.utils.setuptools_build import SETUPTOOLS_SHIM
from pip._internal.utils.temp_dir import TempDirectory
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
from pip._internal.utils.ui import DownloadProgressProvider
from pip._internal.vcs import vcs

if MYPY_CHECK_RUNNING:
from typing import Optional # noqa: F401

try:
import ssl # noqa
except ImportError:
Expand Down Expand Up @@ -321,7 +325,7 @@ def cert_verify(self, conn, url, verify, cert):

class PipSession(requests.Session):

timeout = None
timeout = None # type: Optional[int]

def __init__(self, *args, **kwargs):
retries = kwargs.pop("retries", 0)
Expand Down

0 comments on commit 35701ea

Please sign in to comment.