Skip to content

Commit

Permalink
Merge pull request #8322 from deveshks/mypy-internal-ops
Browse files Browse the repository at this point in the history
Complete type annotations in "pip._internal.operations.{check,freeze}" and "pip._internal.utils.subprocess"
  • Loading branch information
sbidoul authored Jul 5, 2020
2 parents 8db4fc8 + 245bcd0 commit c235044
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
Empty file.
10 changes: 2 additions & 8 deletions src/pip/_internal/operations/check.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
"""Validation of dependencies of packages
"""

# The following comment should be removed at some point in the future.
# mypy: strict-optional=False
# mypy: disallow-untyped-defs=False

import logging
from collections import namedtuple

Expand Down Expand Up @@ -65,9 +61,6 @@ def check_package_set(package_set, should_ignore=None):
If should_ignore is passed, it should be a callable that takes a
package name and returns a boolean.
"""
if should_ignore is None:
def should_ignore(name):
return False

missing = {}
conflicting = {}
Expand All @@ -77,7 +70,7 @@ def should_ignore(name):
missing_deps = set() # type: Set[Missing]
conflicting_deps = set() # type: Set[Conflicting]

if should_ignore(package_name):
if should_ignore and should_ignore(package_name):
continue

for req in package_set[package_name].requires:
Expand Down Expand Up @@ -139,6 +132,7 @@ def _simulate_installation_of(to_install, package_set):
abstract_dist = make_distribution_for_install_requirement(inst_req)
dist = abstract_dist.get_pkg_resources_distribution()

assert dist is not None
name = canonicalize_name(dist.key)
package_set[name] = PackageDetails(dist.version, dist.requires())

Expand Down
20 changes: 10 additions & 10 deletions src/pip/_internal/operations/freeze.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# The following comment should be removed at some point in the future.
# mypy: strict-optional=False
# mypy: disallow-untyped-defs=False

from __future__ import absolute_import

import collections
Expand Down Expand Up @@ -46,8 +42,8 @@
def freeze(
requirement=None, # type: Optional[List[str]]
find_links=None, # type: Optional[List[str]]
local_only=None, # type: Optional[bool]
user_only=None, # type: Optional[bool]
local_only=False, # type: bool
user_only=False, # type: bool
paths=None, # type: Optional[List[str]]
isolated=False, # type: bool
wheel_cache=None, # type: Optional[WheelCache]
Expand All @@ -60,10 +56,13 @@ def freeze(
for link in find_links:
yield '-f {}'.format(link)
installations = {} # type: Dict[str, FrozenRequirement]
for dist in get_installed_distributions(local_only=local_only,
skip=(),
user_only=user_only,
paths=paths):

for dist in get_installed_distributions(
local_only=local_only,
skip=(),
user_only=user_only,
paths=paths
):
try:
req = FrozenRequirement.from_dist(dist)
except RequirementParseError as exc:
Expand Down Expand Up @@ -265,6 +264,7 @@ def from_dist(cls, dist):
return cls(dist.project_name, req, editable, comments=comments)

def __str__(self):
# type: () -> str
req = self.req
if self.editable:
req = '-e {}'.format(req)
Expand Down
7 changes: 4 additions & 3 deletions src/pip/_internal/utils/subprocess.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# The following comment should be removed at some point in the future.
# mypy: strict-optional=False

from __future__ import absolute_import

import logging
Expand Down Expand Up @@ -188,6 +185,8 @@ def call_subprocess(
stderr=subprocess.STDOUT, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, cwd=cwd, env=env,
)
assert proc.stdin
assert proc.stdout
proc.stdin.close()
except Exception as exc:
if log_failed_cmd:
Expand All @@ -208,6 +207,7 @@ def call_subprocess(
log_subprocess(line)
# Update the spinner.
if use_spinner:
assert spinner
spinner.spin()
try:
proc.wait()
Expand All @@ -218,6 +218,7 @@ def call_subprocess(
proc.returncode and proc.returncode not in extra_ok_returncodes
)
if use_spinner:
assert spinner
if proc_had_error:
spinner.finish("error")
else:
Expand Down

0 comments on commit c235044

Please sign in to comment.