1from __future__ import annotations
2
3import os
4from typing import (
5 Any,
6 Dict,
7 Iterator,
8 List,
9 Optional,
10 Protocol,
11 TypeVar,
12 Union,
13 overload,
14)
15
16_T = TypeVar("_T")
17
18
19class PackageMetadata(Protocol):
20 def __len__(self) -> int: ... # pragma: no cover
21
22 def __contains__(self, item: str) -> bool: ... # pragma: no cover
23
24 def __getitem__(self, key: str) -> str: ... # pragma: no cover
25
26 def __iter__(self) -> Iterator[str]: ... # pragma: no cover
27
28 @overload
29 def get(
30 self, name: str, failobj: None = None
31 ) -> Optional[str]: ... # pragma: no cover
32
33 @overload
34 def get(self, name: str, failobj: _T) -> Union[str, _T]: ... # pragma: no cover
35
36 # overload per python/importlib_metadata#435
37 @overload
38 def get_all(
39 self, name: str, failobj: None = None
40 ) -> Optional[List[Any]]: ... # pragma: no cover
41
42 @overload
43 def get_all(self, name: str, failobj: _T) -> Union[List[Any], _T]:
44 """
45 Return all values associated with a possibly multi-valued key.
46 """
47
48 @property
49 def json(self) -> Dict[str, Union[str, List[str]]]:
50 """
51 A JSON-compatible form of the metadata.
52 """
53
54
55class SimplePath(Protocol):
56 """
57 A minimal subset of pathlib.Path required by Distribution.
58 """
59
60 def joinpath(
61 self, other: Union[str, os.PathLike[str]]
62 ) -> SimplePath: ... # pragma: no cover
63
64 def __truediv__(
65 self, other: Union[str, os.PathLike[str]]
66 ) -> SimplePath: ... # pragma: no cover
67
68 @property
69 def parent(self) -> SimplePath: ... # pragma: no cover
70
71 def read_text(self, encoding=None) -> str: ... # pragma: no cover
72
73 def read_bytes(self) -> bytes: ... # pragma: no cover
74
75 def exists(self) -> bool: ... # pragma: no cover