Skip to content

Commit

Permalink
Merge pull request #6093 from mkurnikov/req-types-finished
Browse files Browse the repository at this point in the history
Finish types for pip._internal.req, set disallow_untyped_defs flag
  • Loading branch information
cjerdonek authored Mar 23, 2019
2 parents d245434 + 8c70363 commit 1bb21fd
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 26 deletions.
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ follow_imports = silent
ignore_missing_imports = True
strict_optional = False

[mypy-pip/_internal/req/*]
disallow_untyped_defs = True

[mypy-pip/_vendor/*]
follow_imports = skip
ignore_errors = True
Expand Down
5 changes: 3 additions & 2 deletions src/pip/_internal/req/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pip._internal.utils.typing import MYPY_CHECK_RUNNING

if MYPY_CHECK_RUNNING:
from typing import List, Sequence
from typing import Any, List, Sequence

__all__ = [
"RequirementSet", "InstallRequirement",
Expand All @@ -23,7 +23,8 @@ def install_given_reqs(
to_install, # type: List[InstallRequirement]
install_options, # type: List[str]
global_options=(), # type: Sequence[str]
*args, **kwargs
*args, # type: Any
**kwargs # type: Any
):
# type: (...) -> List[InstallRequirement]
"""
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_internal/req/constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

if MYPY_CHECK_RUNNING:
from typing import (
Optional, Tuple, Set, Any, Union, Dict,
Any, Dict, Optional, Set, Tuple, Union,
)
from pip._internal.cache import WheelCache

Expand Down
3 changes: 2 additions & 1 deletion src/pip/_internal/req/req_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

if MYPY_CHECK_RUNNING:
from typing import (
Iterator, Tuple, Optional, List, Callable, Text
Any, Callable, Iterator, List, NoReturn, Optional, Text, Tuple,
)
from pip._internal.req import InstallRequirement
from pip._internal.cache import WheelCache
Expand Down Expand Up @@ -288,6 +288,7 @@ def build_parser(line):
# By default optparse sys.exits on parsing errors. We want to wrap
# that in our own exception.
def parser_exit(self, msg):
# type: (Any, str) -> NoReturn
# add offending line
msg = 'Invalid requirement: %s\n%s' % (line, msg)
raise RequirementsFileParseError(msg)
Expand Down
15 changes: 13 additions & 2 deletions src/pip/_internal/req/req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

if MYPY_CHECK_RUNNING:
from typing import (
Optional, Iterable, List, Union, Any, Sequence, Dict
Any, Dict, Iterable, List, Mapping, Optional, Sequence, Union,
)
from pip._internal.build_env import BuildEnvironment
from pip._internal.cache import WheelCache
Expand Down Expand Up @@ -156,6 +156,7 @@ def __init__(
self.use_pep517 = use_pep517

def __str__(self):
# type: () -> str
if self.req:
s = str(self.req)
if self.link:
Expand All @@ -176,6 +177,7 @@ def __str__(self):
return s

def __repr__(self):
# type: () -> str
return '<%s object: %s editable=%r>' % (
self.__class__.__name__, str(self), self.editable)

Expand Down Expand Up @@ -226,6 +228,7 @@ def is_pinned(self):

@property
def installed_version(self):
# type: () -> Optional[str]
return get_installed_version(self.name)

def match_markers(self, extras_requested=None):
Expand Down Expand Up @@ -501,7 +504,12 @@ def load_pyproject_toml(self):
# Use a custom function to call subprocesses
self.spin_message = ""

def runner(cmd, cwd=None, extra_environ=None):
def runner(
cmd, # type: List[str]
cwd=None, # type: Optional[str]
extra_environ=None # type: Optional[Mapping[str, Any]]
):
# type: (...) -> None
with open_spinner(self.spin_message) as spinner:
call_subprocess(
cmd,
Expand Down Expand Up @@ -661,6 +669,7 @@ def egg_info_path(self):

@property
def metadata(self):
# type: () -> Any
if not hasattr(self, '_metadata'):
self._metadata = get_metadata(self.get_dist())

Expand Down Expand Up @@ -815,6 +824,7 @@ def uninstall(self, auto_confirm=False, verbose=False,
return uninstalled_pathset

def _clean_zip_name(self, name, prefix): # only used by archive.
# type: (str, str) -> str
assert name.startswith(prefix + os.path.sep), (
"name %r doesn't start with prefix %r" % (name, prefix)
)
Expand Down Expand Up @@ -947,6 +957,7 @@ def install(
self.install_succeeded = True

def prepend_root(path):
# type: (str) -> str
if root is None or not os.path.isabs(path):
return path
else:
Expand Down
4 changes: 3 additions & 1 deletion src/pip/_internal/req/req_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pip._internal.wheel import Wheel

if MYPY_CHECK_RUNNING:
from typing import Optional, List, Tuple, Dict, Iterable
from typing import Dict, Iterable, List, Optional, Tuple
from pip._internal.req.req_install import InstallRequirement


Expand All @@ -34,12 +34,14 @@ def __init__(self, require_hashes=False, check_supported_wheels=True):
self.reqs_to_cleanup = [] # type: List[InstallRequirement]

def __str__(self):
# type: () -> str
reqs = [req for req in self.requirements.values()
if not req.comes_from]
reqs.sort(key=lambda req: req.name.lower())
return ' '.join([str(req.req) for req in reqs])

def __repr__(self):
# type: () -> str
reqs = [req for req in self.requirements.values()]
reqs.sort(key=lambda req: req.name.lower())
reqs_str = ', '.join([str(req.req) for req in reqs])
Expand Down
12 changes: 10 additions & 2 deletions src/pip/_internal/req/req_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from pip._internal.utils.typing import MYPY_CHECK_RUNNING

if MYPY_CHECK_RUNNING:
from typing import Set, Iterator
from types import TracebackType
from typing import Iterator, Optional, Set, Type
from pip._internal.req.req_install import InstallRequirement
from pip._internal.models.link import Link

Expand All @@ -33,9 +34,16 @@ def __init__(self):
self._entries = set() # type: Set[InstallRequirement]

def __enter__(self):
# type: () -> RequirementTracker
return self

def __exit__(self, exc_type, exc_val, exc_tb):
def __exit__(
self,
exc_type, # type: Optional[Type[BaseException]]
exc_val, # type: Optional[BaseException]
exc_tb # type: Optional[TracebackType]
):
# type: (...) -> None
self.cleanup()

def _entry_path(self, link):
Expand Down
Loading

0 comments on commit 1bb21fd

Please sign in to comment.