diff --git a/src/pip/_internal/models/candidate.py b/src/pip/_internal/models/candidate.py index c736de6c9af..4475458ab3d 100644 --- a/src/pip/_internal/models/candidate.py +++ b/src/pip/_internal/models/candidate.py @@ -1,6 +1,12 @@ from pip._vendor.packaging.version import parse as parse_version from pip._internal.utils.models import KeyBasedCompareMixin +from pip._internal.utils.typing import MYPY_CHECK_RUNNING + +if MYPY_CHECK_RUNNING: + from pip._vendor.packaging.version import _BaseVersion # noqa: F401 + from pip._internal.models.link import Link # noqa: F401 + from typing import Any, Union # noqa: F401 class InstallationCandidate(KeyBasedCompareMixin): @@ -8,8 +14,9 @@ class InstallationCandidate(KeyBasedCompareMixin): """ def __init__(self, project, version, location): + # type: (Any, str, Link) -> None self.project = project - self.version = parse_version(version) + self.version = parse_version(version) # type: _BaseVersion self.location = location super(InstallationCandidate, self).__init__( @@ -18,6 +25,7 @@ def __init__(self, project, version, location): ) def __repr__(self): + # type: () -> str return "".format( self.project, self.version, self.location, ) diff --git a/src/pip/_internal/models/index.py b/src/pip/_internal/models/index.py index 870a315ed1d..ead1efbda76 100644 --- a/src/pip/_internal/models/index.py +++ b/src/pip/_internal/models/index.py @@ -6,6 +6,7 @@ class PackageIndex(object): """ def __init__(self, url, file_storage_domain): + # type: (str, str) -> None super(PackageIndex, self).__init__() self.url = url self.netloc = urllib_parse.urlsplit(url).netloc @@ -18,6 +19,7 @@ def __init__(self, url, file_storage_domain): self.file_storage_domain = file_storage_domain def _url_for_path(self, path): + # type: (str) -> str return urllib_parse.urljoin(self.url, path) diff --git a/src/pip/_internal/models/link.py b/src/pip/_internal/models/link.py index 83c72657009..ad2f93e191a 100644 --- a/src/pip/_internal/models/link.py +++ b/src/pip/_internal/models/link.py @@ -8,6 +8,11 @@ WHEEL_EXTENSION, redact_password_from_url, splitext, ) from pip._internal.utils.models import KeyBasedCompareMixin +from pip._internal.utils.typing import MYPY_CHECK_RUNNING + +if MYPY_CHECK_RUNNING: + from typing import Optional, Tuple, Union, Text # noqa: F401 + from pip._internal.index import HTMLPage # noqa: F401 class Link(KeyBasedCompareMixin): @@ -15,6 +20,7 @@ class Link(KeyBasedCompareMixin): """ def __init__(self, url, comes_from=None, requires_python=None): + # type: (str, Optional[Union[str, HTMLPage]], Optional[str]) -> None """ url: url of the resource pointed to (href of the link) @@ -55,6 +61,7 @@ def __repr__(self): @property def filename(self): + # type: () -> str _, netloc, path, _, _ = urllib_parse.urlsplit(self.url) name = posixpath.basename(path.rstrip('/')) or netloc name = urllib_parse.unquote(name) @@ -63,25 +70,31 @@ def filename(self): @property def scheme(self): + # type: () -> str return urllib_parse.urlsplit(self.url)[0] @property def netloc(self): + # type: () -> str return urllib_parse.urlsplit(self.url)[1] @property def path(self): + # type: () -> str return urllib_parse.unquote(urllib_parse.urlsplit(self.url)[2]) def splitext(self): + # type: () -> Tuple[str, str] return splitext(posixpath.basename(self.path.rstrip('/'))) @property def ext(self): + # type: () -> str return self.splitext()[1] @property def url_without_fragment(self): + # type: () -> str scheme, netloc, path, query, fragment = urllib_parse.urlsplit(self.url) return urllib_parse.urlunsplit((scheme, netloc, path, query, None)) @@ -89,6 +102,7 @@ def url_without_fragment(self): @property def egg_fragment(self): + # type: () -> Optional[str] match = self._egg_fragment_re.search(self.url) if not match: return None @@ -98,6 +112,7 @@ def egg_fragment(self): @property def subdirectory_fragment(self): + # type: () -> Optional[str] match = self._subdirectory_fragment_re.search(self.url) if not match: return None @@ -109,6 +124,7 @@ def subdirectory_fragment(self): @property def hash(self): + # type: () -> Optional[str] match = self._hash_re.search(self.url) if match: return match.group(2) @@ -116,6 +132,7 @@ def hash(self): @property def hash_name(self): + # type: () -> Optional[str] match = self._hash_re.search(self.url) if match: return match.group(1) @@ -123,14 +140,17 @@ def hash_name(self): @property def show_url(self): + # type: () -> Optional[str] return posixpath.basename(self.url.split('#', 1)[0].split('?', 1)[0]) @property def is_wheel(self): + # type: () -> bool return self.ext == WHEEL_EXTENSION @property def is_artifact(self): + # type: () -> bool """ Determines if this points to an actual artifact (e.g. a tarball) or if it points to an "abstract" thing like a path or a VCS location.