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