Skip to content

Commit 5a4699d

Browse files
authored
Merge pull request #315 from FFY00/pathdistribution-type-hint
meta: add SimplePath protocol for PathDistribution
2 parents 335a758 + 92084b8 commit 5a4699d

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ v4.1.0
33

44
* #312: Add support for metadata 2.2 (``Dynamic`` field).
55

6+
* #315: Add ``SimplePath`` protocol for interface clarity
7+
in ``PathDistribution``.
8+
69
v4.0.1
710
=======
811

importlib_metadata/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
)
2424
from ._functools import method_cache
2525
from ._itertools import unique_everseen
26-
from ._meta import PackageMetadata
26+
from ._meta import PackageMetadata, SimplePath
2727

2828
from contextlib import suppress
2929
from importlib import import_module
@@ -783,11 +783,10 @@ def invalidate_caches(cls):
783783

784784

785785
class PathDistribution(Distribution):
786-
def __init__(self, path):
787-
"""Construct a distribution from a path to the metadata directory.
786+
def __init__(self, path: SimplePath):
787+
"""Construct a distribution.
788788
789-
:param path: A pathlib.Path or similar object supporting
790-
.joinpath(), __div__, .parent, and .read_text().
789+
:param path: SimplePath indicating the metadata directory.
791790
"""
792791
self._path = path
793792

importlib_metadata/_meta.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,21 @@ def json(self) -> Dict[str, Union[str, List[str]]]:
2828
"""
2929
A JSON-compatible form of the metadata.
3030
"""
31+
32+
33+
class SimplePath(Protocol):
34+
"""
35+
A minimal subset of pathlib.Path required by PathDistribution.
36+
"""
37+
38+
def joinpath(self) -> 'SimplePath':
39+
... # pragma: no cover
40+
41+
def __div__(self) -> 'SimplePath':
42+
... # pragma: no cover
43+
44+
def parent(self) -> 'SimplePath':
45+
... # pragma: no cover
46+
47+
def read_text(self) -> str:
48+
... # pragma: no cover

0 commit comments

Comments
 (0)