Skip to content

Commit

Permalink
Corrected the interface for SimplePath to encompass the expectations …
Browse files Browse the repository at this point in the history
…of locate_file and PackagePath.
  • Loading branch information
jaraco committed Dec 16, 2023
1 parent fc4df51 commit 1b3f272
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
8 changes: 4 additions & 4 deletions importlib_metadata/__init__.py
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
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
@@ -0,0 +1 @@
Corrected the interface for SimplePath to encompass the expectations of locate_file and PackagePath.

0 comments on commit 1b3f272

Please sign in to comment.