Skip to content

Commit

Permalink
Fix the pip/_internal/distributions annotations (#10074)
Browse files Browse the repository at this point in the history
  • Loading branch information
DiddiLeija authored Jul 12, 2021
1 parent ce86dc8 commit 3b3fde2
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 24 deletions.
1 change: 1 addition & 0 deletions news/10074.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed all the annotations from ``pip/_internal/distributions``.
5 changes: 3 additions & 2 deletions src/pip/_internal/distributions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
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.
Expand Down
11 changes: 5 additions & 6 deletions src/pip/_internal/distributions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
8 changes: 4 additions & 4 deletions src/pip/_internal/distributions/installed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 8 additions & 8 deletions src/pip/_internal/distributions/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -35,10 +35,10 @@ def prepare_distribution_metadata(self, finder, build_isolation):

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}."
Expand Down
8 changes: 4 additions & 4 deletions src/pip/_internal/distributions/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -29,6 +28,7 @@ def get_pkg_resources_distribution(self):
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

0 comments on commit 3b3fde2

Please sign in to comment.