Skip to content

Commit 200cf45

Browse files
authored
Merge pull request #480 from python/bugfix/distribution-simplepath
Correct the interface for SimplePath
2 parents fc4df51 + ac243d3 commit 200cf45

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

docs/api.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ API Reference
99
:members:
1010
:undoc-members:
1111
:show-inheritance:
12+
13+
.. automodule:: importlib_metadata._meta
14+
:members:
15+
:undoc-members:
16+
:show-inheritance:

docs/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,6 @@
7171
('py:class', '_T'),
7272
# Other workarounds
7373
('py:class', 'importlib_metadata.DeprecatedNonAbstract'),
74+
# Workaround needed for #480
75+
('py:obj', 'importlib_metadata._meta._T'),
7476
]

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)