diff --git a/src/pip/_internal/resolution/resolvelib/candidates.py b/src/pip/_internal/resolution/resolvelib/candidates.py index 6abadf04d..3f431843f 100644 --- a/src/pip/_internal/resolution/resolvelib/candidates.py +++ b/src/pip/_internal/resolution/resolvelib/candidates.py @@ -28,6 +28,12 @@ if MYPY_CHECK_RUNNING: from .base import Requirement from .factory import Factory + BaseCandidate = Union[ + "AlreadyInstalledCandidate", + "EditableCandidate", + "LinkCandidate", + ] + logger = logging.getLogger(__name__) @@ -54,7 +60,10 @@ def make_install_req_from_editable(link, parent): assert parent.editable, "parent not editable" return install_req_from_editable( link.url, - comes_from=parent.comes_from, + # HACK: install_req_from_editable accepts Optional[str] here, but + # parent.comes_from is Union[str, InstallRequirement, None]. How do + # we fix the type hint conflicts? + comes_from=parent.comes_from, # type: ignore use_pep517=parent.use_pep517, isolated=parent.isolated, constraint=parent.constraint, @@ -302,7 +311,7 @@ class ExtrasCandidate(Candidate): """ def __init__( self, - base, # type: Union[AlreadyInstalledCandidate, LinkCandidate] + base, # type: BaseCandidate extras, # type: Set[str] ): # type: (...) -> None diff --git a/src/pip/_internal/resolution/resolvelib/factory.py b/src/pip/_internal/resolution/resolvelib/factory.py index 705f47f13..cf5b2b19e 100644 --- a/src/pip/_internal/resolution/resolvelib/factory.py +++ b/src/pip/_internal/resolution/resolvelib/factory.py @@ -34,6 +34,7 @@ if MYPY_CHECK_RUNNING: from pip._internal.resolution.base import InstallRequirementProvider from .base import Candidate, Requirement + from .candidates import BaseCandidate C = TypeVar("C") Cache = Dict[Link, C] @@ -85,7 +86,7 @@ class Factory(object): self._editable_candidate_cache[link] = EditableCandidate( link, parent, factory=self, name=name, version=version, ) - base = self._editable_candidate_cache[link] + base = self._editable_candidate_cache[link] # type: BaseCandidate else: if link not in self._link_candidate_cache: self._link_candidate_cache[link] = LinkCandidate(