_meta.py 1.8 KB

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