_meta.py 1.8 KB

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