_meta.py 1.6 KB

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