Skip to content

Commit c3d3a98

Browse files
authored
Merge pull request #10508 from jdufresne/fix-types
Fix new mypy failures in tests/unit/resolution_resolvelib/
2 parents cb66b03 + dadc9fc commit c3d3a98

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

news/9951f555-1210-4fd3-9a37-fc301a12e9f5.trivial.rst

Whitespace-only changes.

src/pip/_internal/resolution/resolvelib/provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def get_preference(
7171
identifier: str,
7272
resolutions: Mapping[str, Candidate],
7373
candidates: Mapping[str, Iterator[Candidate]],
74-
information: Mapping[str, Iterator["PreferenceInformation"]],
74+
information: Mapping[str, Iterable["PreferenceInformation"]],
7575
) -> "Preference":
7676
"""Produce a sort key for given requirement based on preference.
7777

tests/unit/resolution_resolvelib/test_provider.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
1+
from typing import TYPE_CHECKING, List, Optional
2+
13
from pip._vendor.resolvelib.resolvers import RequirementInformation
24

35
from pip._internal.models.candidate import InstallationCandidate
46
from pip._internal.models.link import Link
57
from pip._internal.req.constructors import install_req_from_req_string
8+
from pip._internal.resolution.resolvelib.factory import Factory
69
from pip._internal.resolution.resolvelib.provider import PipProvider
710
from pip._internal.resolution.resolvelib.requirements import SpecifierRequirement
811

12+
if TYPE_CHECKING:
13+
from pip._internal.resolution.resolvelib.provider import PreferenceInformation
14+
915

10-
def build_requirement_information(name, parent):
16+
def build_requirement_information(
17+
name: str, parent: Optional[InstallationCandidate]
18+
) -> List["PreferenceInformation"]:
1119
install_requirement = install_req_from_req_string(name)
12-
requirement_information = RequirementInformation(
13-
requirement=SpecifierRequirement(install_requirement), parent=parent
20+
# RequirementInformation is typed as a tuple, but it is a namedtupled.
21+
# https://github.com/sarugaku/resolvelib/blob/7bc025aa2a4e979597c438ad7b17d2e8a08a364e/src/resolvelib/resolvers.pyi#L20-L22
22+
requirement_information: PreferenceInformation = RequirementInformation(
23+
requirement=SpecifierRequirement(install_requirement), # type: ignore[call-arg]
24+
parent=parent,
1425
)
1526
return [requirement_information]
1627

1728

18-
def test_provider_known_depths(factory):
29+
def test_provider_known_depths(factory: Factory) -> None:
1930
# Root requirement is specified by the user
2031
# therefore has an infered depth of 1
2132
root_requirement_name = "my-package"

0 commit comments

Comments
 (0)