Skip to content

Commit 1b3f272

Browse files
committed
Corrected the interface for SimplePath to encompass the expectations of locate_file and PackagePath.
1 parent fc4df51 commit 1b3f272

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

importlib_metadata/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def read_text(self, encoding: str = 'utf-8') -> str: # type: ignore[override]
320320
def read_binary(self) -> bytes:
321321
return self.locate().read_bytes()
322322

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

@@ -387,9 +387,9 @@ def read_text(self, filename) -> Optional[str]:
387387
"""
388388

389389
@abc.abstractmethod
390-
def locate_file(self, path: StrPath) -> pathlib.Path:
390+
def locate_file(self, path: StrPath) -> SimplePath:
391391
"""
392-
Given a path to a file in this distribution, return a path
392+
Given a path to a file in this distribution, return a SimplePath
393393
to it.
394394
"""
395395

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

855855
read_text.__doc__ = Distribution.read_text.__doc__
856856

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

860860
@property

importlib_metadata/_meta.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def json(self) -> Dict[str, Union[str, List[str]]]:
4646

4747
class SimplePath(Protocol[_T]):
4848
"""
49-
A minimal subset of pathlib.Path required by PathDistribution.
49+
A minimal subset of pathlib.Path required by Distribution.
5050
"""
5151

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

62-
def read_text(self) -> str:
62+
def read_text(self, encoding=None) -> str:
63+
... # pragma: no cover
64+
65+
def read_bytes(self) -> bytes:
66+
... # pragma: no cover
67+
68+
def exists(self) -> bool:
6369
... # pragma: no cover

newsfragments/+b15724f6.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Corrected the interface for SimplePath to encompass the expectations of locate_file and PackagePath.

0 commit comments

Comments
 (0)