Skip to content

Commit

Permalink
Merge pull request #480 from python/bugfix/distribution-simplepath
Browse files Browse the repository at this point in the history
Correct the interface for SimplePath
  • Loading branch information
jaraco authored Dec 16, 2023
2 parents fc4df51 + ac243d3 commit 200cf45
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
5 changes: 5 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ API Reference
:members:
:undoc-members:
:show-inheritance:

.. automodule:: importlib_metadata._meta
:members:
:undoc-members:
:show-inheritance:
2 changes: 2 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,6 @@
('py:class', '_T'),
# Other workarounds
('py:class', 'importlib_metadata.DeprecatedNonAbstract'),
# Workaround needed for #480
('py:obj', 'importlib_metadata._meta._T'),
]
8 changes: 4 additions & 4 deletions importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def read_text(self, encoding: str = 'utf-8') -> str: # type: ignore[override]
def read_binary(self) -> bytes:
return self.locate().read_bytes()

def locate(self) -> pathlib.Path:
def locate(self) -> SimplePath:
"""Return a path-like object for this path"""
return self.dist.locate_file(self)

Expand Down Expand Up @@ -387,9 +387,9 @@ def read_text(self, filename) -> Optional[str]:
"""

@abc.abstractmethod
def locate_file(self, path: StrPath) -> pathlib.Path:
def locate_file(self, path: StrPath) -> SimplePath:
"""
Given a path to a file in this distribution, return a path
Given a path to a file in this distribution, return a SimplePath
to it.
"""

Expand Down Expand Up @@ -854,7 +854,7 @@ def read_text(self, filename: StrPath) -> Optional[str]:

read_text.__doc__ = Distribution.read_text.__doc__

def locate_file(self, path: StrPath) -> pathlib.Path:
def locate_file(self, path: StrPath) -> SimplePath:
return self._path.parent / path

@property
Expand Down
10 changes: 8 additions & 2 deletions importlib_metadata/_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def json(self) -> Dict[str, Union[str, List[str]]]:

class SimplePath(Protocol[_T]):
"""
A minimal subset of pathlib.Path required by PathDistribution.
A minimal subset of pathlib.Path required by Distribution.
"""

def joinpath(self, other: Union[str, _T]) -> _T:
Expand All @@ -59,5 +59,11 @@ def __truediv__(self, other: Union[str, _T]) -> _T:
def parent(self) -> _T:
... # pragma: no cover

def read_text(self) -> str:
def read_text(self, encoding=None) -> str:
... # pragma: no cover

def read_bytes(self) -> bytes:
... # pragma: no cover

def exists(self) -> bool:
... # pragma: no cover
1 change: 1 addition & 0 deletions newsfragments/+b15724f6.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Corrected the interface for SimplePath to encompass the expectations of locate_file and PackagePath.

0 comments on commit 200cf45

Please sign in to comment.