Type hint hacks

This commit is contained in:
Tzu-ping Chung 2020-04-04 18:12:38 +08:00
parent 2430aba879
commit 05f7dbd0c8
2 changed files with 13 additions and 3 deletions

View File

@ -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

View File

@ -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(