_meta.py 1.7 KB

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