codekingpro/portable-devtools
114k
1from __future__ import annotations2 3import os4from collections.abc import Iterator5from typing import (6 Any,7 Protocol,8 TypeVar,9 overload,10)11 12_T = TypeVar("_T")13 14 15class PackageMetadata(Protocol):16 def __len__(self) -> int: ... # pragma: no cover17 18 def __contains__(self, item: str) -> bool: ... # pragma: no cover19 20 def __getitem__(self, key: str) -> str: ... # pragma: no cover21 22 def __iter__(self) -> Iterator[str]: ... # pragma: no cover23 24 @overload25 def get(26 self, name: str, failobj: None = None27 ) -> str | None: ... # pragma: no cover28 29 @overload30 def get(self, name: str, failobj: _T) -> str | _T: ... # pragma: no cover31 32 # overload per python/importlib_metadata#43533 @overload34 def get_all(35 self, name: str, failobj: None = None36 ) -> list[Any] | None: ... # pragma: no cover37 38 @overload39 def get_all(self, name: str, failobj: _T) -> list[Any] | _T:40 """41 Return all values associated with a possibly multi-valued key.42 """43 44 @property45 def json(self) -> dict[str, str | list[str]]:46 """47 A JSON-compatible form of the metadata.48 """49 50 51class SimplePath(Protocol):52 """53 A minimal subset of pathlib.Path required by Distribution.54 """55 56 def joinpath(57 self, other: str | os.PathLike[str]58 ) -> SimplePath: ... # pragma: no cover59 60 def __truediv__(61 self, other: str | os.PathLike[str]62 ) -> SimplePath: ... # pragma: no cover63 64 @property65 def parent(self) -> SimplePath: ... # pragma: no cover66 67 def read_text(self, encoding=None) -> str: ... # pragma: no cover68 69 def read_bytes(self) -> bytes: ... # pragma: no cover70 71 def exists(self) -> bool: ... # pragma: no cover72 