Fix the `pip/_internal/distributions` annotations (#10074)

This commit is contained in:
Diego Ramirez 2021-07-12 17:29:21 -05:00 committed by GitHub
parent ce86dc86d6
commit 3b3fde2447
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 24 deletions

1
news/10074.trivial.rst Normal file
View File

@ -0,0 +1 @@
Fixed all the annotations from ``pip/_internal/distributions``.

View File

@ -4,8 +4,9 @@ from pip._internal.distributions.wheel import WheelDistribution
from pip._internal.req.req_install import InstallRequirement
def make_distribution_for_install_requirement(install_req):
# type: (InstallRequirement) -> AbstractDistribution
def make_distribution_for_install_requirement(
install_req: InstallRequirement,
) -> AbstractDistribution:
"""Returns a Distribution for the given InstallRequirement"""
# Editable requirements will always be source distributions. They use the
# legacy logic until we create a modern standard for them.

View File

@ -23,17 +23,16 @@ class AbstractDistribution(metaclass=abc.ABCMeta):
above metadata.
"""
def __init__(self, req):
# type: (InstallRequirement) -> None
def __init__(self, req: InstallRequirement) -> None:
super().__init__()
self.req = req
@abc.abstractmethod
def get_pkg_resources_distribution(self):
# type: () -> Optional[Distribution]
def get_pkg_resources_distribution(self) -> Optional[Distribution]:
raise NotImplementedError()
@abc.abstractmethod
def prepare_distribution_metadata(self, finder, build_isolation):
# type: (PackageFinder, bool) -> None
def prepare_distribution_metadata(
self, finder: PackageFinder, build_isolation: bool
) -> None:
raise NotImplementedError()

View File

@ -13,10 +13,10 @@ class InstalledDistribution(AbstractDistribution):
been computed.
"""
def get_pkg_resources_distribution(self):
# type: () -> Optional[Distribution]
def get_pkg_resources_distribution(self) -> Optional[Distribution]:
return self.req.satisfied_by
def prepare_distribution_metadata(self, finder, build_isolation):
# type: (PackageFinder, bool) -> None
def prepare_distribution_metadata(
self, finder: PackageFinder, build_isolation: bool
) -> None:
pass

View File

@ -19,12 +19,12 @@ class SourceDistribution(AbstractDistribution):
generated, either using PEP 517 or using the legacy `setup.py egg_info`.
"""
def get_pkg_resources_distribution(self):
# type: () -> Distribution
def get_pkg_resources_distribution(self) -> Distribution:
return self.req.get_dist()
def prepare_distribution_metadata(self, finder, build_isolation):
# type: (PackageFinder, bool) -> None
def prepare_distribution_metadata(
self, finder: PackageFinder, build_isolation: bool
) -> None:
# Load pyproject.toml, to determine whether PEP 517 is to be used
self.req.load_pyproject_toml()
@ -35,10 +35,10 @@ class SourceDistribution(AbstractDistribution):
self.req.prepare_metadata()
def _setup_isolation(self, finder):
# type: (PackageFinder) -> None
def _raise_conflicts(conflicting_with, conflicting_reqs):
# type: (str, Set[Tuple[str, str]]) -> None
def _setup_isolation(self, finder: PackageFinder) -> None:
def _raise_conflicts(
conflicting_with: str, conflicting_reqs: Set[Tuple[str, str]]
) -> None:
format_string = (
"Some build dependencies for {requirement} "
"conflict with {conflicting_with}: {description}."

View File

@ -13,8 +13,7 @@ class WheelDistribution(AbstractDistribution):
This does not need any preparation as wheels can be directly unpacked.
"""
def get_pkg_resources_distribution(self):
# type: () -> Distribution
def get_pkg_resources_distribution(self) -> Distribution:
"""Loads the metadata from the wheel file into memory and returns a
Distribution that uses it, not relying on the wheel file or
requirement.
@ -29,6 +28,7 @@ class WheelDistribution(AbstractDistribution):
z, self.req.name, self.req.local_file_path
)
def prepare_distribution_metadata(self, finder, build_isolation):
# type: (PackageFinder, bool) -> None
def prepare_distribution_metadata(
self, finder: PackageFinder, build_isolation: bool
) -> None:
pass