Skip to content

Commit

Permalink
Fix type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
notatallshaw committed Oct 11, 2024
1 parent 7cc013b commit 167e384
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/pip/_internal/resolution/resolvelib/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ def get_installation_error(
# The simplest case is when we have *one* cause that can't be
# satisfied. We just report that case.
if len(e.causes) == 1:
req, parent = e.causes[0]
req, parent = next(iter(e.causes))
if req.name not in constraints:
return self._report_single_requirement_conflict(req, parent)

Expand Down
8 changes: 5 additions & 3 deletions src/pip/_internal/resolution/resolvelib/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
logger = getLogger(__name__)


class PipReporter(BaseReporter):
class PipReporter(BaseReporter[Requirement, Candidate, Any]):
def __init__(self) -> None:
self.reject_count_by_package: DefaultDict[str, int] = defaultdict(int)

Expand Down Expand Up @@ -55,7 +55,7 @@ def rejecting_candidate(self, criterion: Any, candidate: Candidate) -> None:
logger.debug(msg)


class PipDebuggingReporter(BaseReporter):
class PipDebuggingReporter(BaseReporter[Requirement, Candidate, Any]):
"""A reporter that does an info log for every event it sees."""

def starting(self) -> None:
Expand All @@ -71,7 +71,9 @@ def ending_round(self, index: int, state: Any) -> None:
def ending(self, state: Any) -> None:
logger.info("Reporter.ending(%r)", state)

def adding_requirement(self, requirement: Requirement, parent: Candidate) -> None:
def adding_requirement(
self, requirement: Requirement, parent: Candidate | None
) -> None:
logger.info("Reporter.adding_requirement(%r, %r)", requirement, parent)

def rejecting_candidate(self, criterion: Any, candidate: Candidate) -> None:
Expand Down
4 changes: 2 additions & 2 deletions src/pip/_internal/resolution/resolvelib/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import functools
import logging
import os
from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple, cast
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Set, Tuple, cast

from pip._vendor.packaging.utils import canonicalize_name
from pip._vendor.resolvelib import BaseReporter, ResolutionImpossible
Expand Down Expand Up @@ -82,7 +82,7 @@ def resolve(
user_requested=collected.user_requested,
)
if "PIP_RESOLVER_DEBUG" in os.environ:
reporter: BaseReporter = PipDebuggingReporter()
reporter: BaseReporter[Requirement, Candidate, Any] = PipDebuggingReporter()
else:
reporter = PipReporter()
resolver: RLResolver[Requirement, Candidate, str] = RLResolver(
Expand Down
8 changes: 5 additions & 3 deletions tests/unit/resolution_resolvelib/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pip._internal.models.candidate import InstallationCandidate
from pip._internal.models.link import Link
from pip._internal.req.constructors import install_req_from_req_string
from pip._internal.resolution.resolvelib.base import Candidate
from pip._internal.resolution.resolvelib.factory import Factory
from pip._internal.resolution.resolvelib.provider import PipProvider
from pip._internal.resolution.resolvelib.requirements import SpecifierRequirement
Expand All @@ -14,13 +15,13 @@


def build_requirement_information(
name: str, parent: Optional[InstallationCandidate]
name: str, parent: Optional[Candidate]
) -> List["PreferenceInformation"]:
install_requirement = install_req_from_req_string(name)
# RequirementInformation is typed as a tuple, but it is a namedtupled.
# https://github.com/sarugaku/resolvelib/blob/7bc025aa2a4e979597c438ad7b17d2e8a08a364e/src/resolvelib/resolvers.pyi#L20-L22
requirement_information: PreferenceInformation = RequirementInformation(
requirement=SpecifierRequirement(install_requirement), # type: ignore[call-arg]
requirement=SpecifierRequirement(install_requirement),
parent=parent,
)
return [requirement_information]
Expand Down Expand Up @@ -60,7 +61,8 @@ def test_provider_known_depths(factory: Factory) -> None:
transitive_requirement_name = "my-transitive-package"

transitive_package_information = build_requirement_information(
name=transitive_requirement_name, parent=root_package_candidate
name=transitive_requirement_name,
parent=root_package_candidate, # type: ignore
)
provider.get_preference(
identifier=transitive_requirement_name,
Expand Down

0 comments on commit 167e384

Please sign in to comment.