Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

86 rader
2.4 KiB

  1. import sys
  2. from typing import Any
  3. from typing import Hashable
  4. from typing import Iterable
  5. from typing import Iterator
  6. from typing import NoReturn
  7. from typing import Optional
  8. from typing import Tuple
  9. from typing import TypeVar
  10. from typing import Union
  11. from typing import overload
  12. if sys.version_info >= (3, 8):
  13. from typing import Protocol
  14. from typing import TYPE_CHECKING
  15. else:
  16. from typing_extensions import Protocol
  17. from typing_extensions import TYPE_CHECKING
  18. if TYPE_CHECKING:
  19. from ._map import Map
  20. HT = TypeVar('HT', bound=Hashable)
  21. KT = TypeVar('KT', bound=Hashable)
  22. KT_co = TypeVar('KT_co', covariant=True)
  23. MM = TypeVar('MM', bound='MapMutation[Any, Any]')
  24. T = TypeVar('T')
  25. VT = TypeVar('VT')
  26. VT_co = TypeVar('VT_co', covariant=True)
  27. class MapKeys(Protocol[KT_co]):
  28. def __len__(self) -> int: ...
  29. def __iter__(self) -> Iterator[KT_co]: ...
  30. class MapValues(Protocol[VT_co]):
  31. def __len__(self) -> int: ...
  32. def __iter__(self) -> Iterator[VT_co]: ...
  33. class MapItems(Protocol[KT_co, VT_co]):
  34. def __len__(self) -> int: ...
  35. def __iter__(self) -> Iterator[Tuple[KT_co, VT_co]]: ...
  36. class IterableItems(Protocol[KT_co, VT_co]):
  37. def items(self) -> Iterable[Tuple[KT_co, VT_co]]: ...
  38. class MapMutation(Protocol[KT, VT]):
  39. def set(self, key: KT, val: VT) -> None: ...
  40. def __enter__(self: MM) -> MM: ...
  41. def __exit__(self, *exc: Any) -> bool: ...
  42. def __iter__(self) -> NoReturn: ...
  43. def __delitem__(self, key: KT) -> None: ...
  44. def __setitem__(self, key: KT, val: VT) -> None: ...
  45. @overload
  46. def pop(self, __key: KT) -> VT: ...
  47. @overload
  48. def pop(self, __key: KT, __default: T) -> Union[VT, T]: ...
  49. @overload
  50. def get(self, key: KT) -> Optional[VT]: ...
  51. @overload
  52. def get(self, key: KT, default: Union[VT, T]) -> Union[VT, T]: ...
  53. def __getitem__(self, key: KT) -> VT: ...
  54. def __contains__(self, key: object) -> bool: ...
  55. @overload
  56. def update(
  57. self,
  58. __col: Union[IterableItems[KT, VT], Iterable[Tuple[KT, VT]]]
  59. ) -> None: ...
  60. @overload
  61. def update(
  62. self: 'MapMutation[Union[HT, str], Any]',
  63. __col: Union[IterableItems[KT, VT], Iterable[Tuple[KT, VT]]],
  64. **kw: VT
  65. ) -> None: ...
  66. @overload
  67. def update(self: 'MapMutation[Union[HT, str], Any]', **kw: VT) -> None: ...
  68. def finish(self) -> 'Map[KT, VT]': ...
  69. def __len__(self) -> int: ...
  70. def __eq__(self, other: Any) -> bool: ...