Skip to content

Commit fa20a0a

Browse files
committed
meta: add Path protocol for PathDistribution
This is needed to properly annotate code that uses PathDistribution, otherwise I need to keep redefining the protocol in my code. Signed-off-by: Filipe Laíns <[email protected]>
1 parent e99cd3c commit fa20a0a

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

importlib_metadata/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import collections
1616

1717
from . import _adapters, _meta
18-
from ._meta import PackageMetadata
18+
from ._meta import PackageMetadata, Path
1919
from ._collections import FreezableDefaultDict, Pair
2020
from ._compat import (
2121
NullFinder,
@@ -783,7 +783,7 @@ def invalidate_caches(cls):
783783

784784

785785
class PathDistribution(Distribution):
786-
def __init__(self, path):
786+
def __init__(self, path: Path):
787787
"""Construct a distribution from a path to the metadata directory.
788788
789789
:param path: A pathlib.Path or similar object supporting

importlib_metadata/_meta.py

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

0 commit comments

Comments
 (0)