typing.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. """Helpers for use with type annotation.
  2. Use the empty classes in this module when annotating the types of Pyrsistent
  3. objects, instead of using the actual collection class.
  4. For example,
  5. from pyrsistent import pvector
  6. from pyrsistent.typing import PVector
  7. myvector: PVector[str] = pvector(['a', 'b', 'c'])
  8. """
  9. from __future__ import absolute_import
  10. try:
  11. from typing import Container
  12. from typing import Hashable
  13. from typing import Generic
  14. from typing import Iterable
  15. from typing import Mapping
  16. from typing import Sequence
  17. from typing import Sized
  18. from typing import TypeVar
  19. __all__ = [
  20. 'CheckedPMap',
  21. 'CheckedPSet',
  22. 'CheckedPVector',
  23. 'PBag',
  24. 'PDeque',
  25. 'PList',
  26. 'PMap',
  27. 'PSet',
  28. 'PVector',
  29. ]
  30. T = TypeVar('T')
  31. KT = TypeVar('KT')
  32. VT = TypeVar('VT')
  33. class CheckedPMap(Mapping[KT, VT], Hashable):
  34. pass
  35. # PSet.add and PSet.discard have different type signatures than that of Set.
  36. class CheckedPSet(Generic[T], Hashable):
  37. pass
  38. class CheckedPVector(Sequence[T], Hashable):
  39. pass
  40. class PBag(Container[T], Iterable[T], Sized, Hashable):
  41. pass
  42. class PDeque(Sequence[T], Hashable):
  43. pass
  44. class PList(Sequence[T], Hashable):
  45. pass
  46. class PMap(Mapping[KT, VT], Hashable):
  47. pass
  48. # PSet.add and PSet.discard have different type signatures than that of Set.
  49. class PSet(Generic[T], Hashable):
  50. pass
  51. class PVector(Sequence[T], Hashable):
  52. pass
  53. class PVectorEvolver(Generic[T]):
  54. pass
  55. class PMapEvolver(Generic[KT, VT]):
  56. pass
  57. class PSetEvolver(Generic[T]):
  58. pass
  59. except ImportError:
  60. pass