codekingpro/portable-devtools
114k
1from __future__ import annotations2 3import os4from typing import Protocol5from typing import Any, Dict, Iterator, List, Optional, TypeVar, Union, overload6 7 8_T = TypeVar("_T")9 10 11class PackageMetadata(Protocol):12 def __len__(self) -> int: ... # pragma: no cover13 14 def __contains__(self, item: str) -> bool: ... # pragma: no cover15 16 def __getitem__(self, key: str) -> str: ... # pragma: no cover17 18 def __iter__(self) -> Iterator[str]: ... # pragma: no cover19 20 @overload21 def get(22 self, name: str, failobj: None = None23 ) -> Optional[str]: ... # pragma: no cover24 25 @overload26 def get(self, name: str, failobj: _T) -> Union[str, _T]: ... # pragma: no cover27 28 # overload per python/importlib_metadata#43529 @overload30 def get_all(31 self, name: str, failobj: None = None32 ) -> Optional[List[Any]]: ... # pragma: no cover33 34 @overload35 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 @property41 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 cover55 56 def __truediv__(57 self, other: Union[str, os.PathLike[str]]58 ) -> SimplePath: ... # pragma: no cover59 60 @property61 def parent(self) -> SimplePath: ... # pragma: no cover62 63 def read_text(self, encoding=None) -> str: ... # pragma: no cover64 65 def read_bytes(self) -> bytes: ... # pragma: no cover66 67 def exists(self) -> bool: ... # pragma: no cover68 