_meta.py 1.8 KB

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