_pep440.pyi 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import re
  2. from collections.abc import Callable
  3. from typing import (
  4. Any,
  5. ClassVar,
  6. Final,
  7. Generic,
  8. NamedTuple,
  9. TypeVar,
  10. final,
  11. type_check_only,
  12. )
  13. from typing import (
  14. Literal as L,
  15. )
  16. from typing_extensions import TypeIs
  17. __all__ = ["VERSION_PATTERN", "InvalidVersion", "LegacyVersion", "Version", "parse"]
  18. ###
  19. _CmpKeyT = TypeVar("_CmpKeyT", bound=tuple[object, ...])
  20. _CmpKeyT_co = TypeVar("_CmpKeyT_co", bound=tuple[object, ...], default=tuple[Any, ...], covariant=True)
  21. ###
  22. VERSION_PATTERN: Final[str] = ...
  23. class InvalidVersion(ValueError): ...
  24. @type_check_only
  25. @final
  26. class _InfinityType:
  27. def __hash__(self) -> int: ...
  28. def __eq__(self, other: object, /) -> TypeIs[_InfinityType]: ...
  29. def __ne__(self, other: object, /) -> bool: ...
  30. def __lt__(self, other: object, /) -> L[False]: ...
  31. def __le__(self, other: object, /) -> L[False]: ...
  32. def __gt__(self, other: object, /) -> L[True]: ...
  33. def __ge__(self, other: object, /) -> L[True]: ...
  34. def __neg__(self) -> _NegativeInfinityType: ...
  35. Infinity: Final[_InfinityType] = ...
  36. @type_check_only
  37. @final
  38. class _NegativeInfinityType:
  39. def __hash__(self) -> int: ...
  40. def __eq__(self, other: object, /) -> TypeIs[_NegativeInfinityType]: ...
  41. def __ne__(self, other: object, /) -> bool: ...
  42. def __lt__(self, other: object, /) -> L[True]: ...
  43. def __le__(self, other: object, /) -> L[True]: ...
  44. def __gt__(self, other: object, /) -> L[False]: ...
  45. def __ge__(self, other: object, /) -> L[False]: ...
  46. def __neg__(self) -> _InfinityType: ...
  47. NegativeInfinity: Final[_NegativeInfinityType] = ...
  48. class _Version(NamedTuple):
  49. epoch: int
  50. release: tuple[int, ...]
  51. dev: tuple[str, int] | None
  52. pre: tuple[str, int] | None
  53. post: tuple[str, int] | None
  54. local: tuple[str | int, ...] | None
  55. class _BaseVersion(Generic[_CmpKeyT_co]):
  56. _key: _CmpKeyT_co
  57. def __hash__(self) -> int: ...
  58. def __eq__(self, other: _BaseVersion, /) -> bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
  59. def __ne__(self, other: _BaseVersion, /) -> bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
  60. def __lt__(self, other: _BaseVersion, /) -> bool: ...
  61. def __le__(self, other: _BaseVersion, /) -> bool: ...
  62. def __ge__(self, other: _BaseVersion, /) -> bool: ...
  63. def __gt__(self, other: _BaseVersion, /) -> bool: ...
  64. def _compare(self, /, other: _BaseVersion[_CmpKeyT], method: Callable[[_CmpKeyT_co, _CmpKeyT], bool]) -> bool: ...
  65. class LegacyVersion(_BaseVersion[tuple[L[-1], tuple[str, ...]]]):
  66. _version: Final[str]
  67. def __init__(self, /, version: str) -> None: ...
  68. @property
  69. def public(self) -> str: ...
  70. @property
  71. def base_version(self) -> str: ...
  72. @property
  73. def local(self) -> None: ...
  74. @property
  75. def is_prerelease(self) -> L[False]: ...
  76. @property
  77. def is_postrelease(self) -> L[False]: ...
  78. class Version(
  79. _BaseVersion[
  80. tuple[
  81. int, # epoch
  82. tuple[int, ...], # release
  83. tuple[str, int] | _InfinityType | _NegativeInfinityType, # pre
  84. tuple[str, int] | _NegativeInfinityType, # post
  85. tuple[str, int] | _InfinityType, # dev
  86. tuple[tuple[int, L[""]] | tuple[_NegativeInfinityType, str], ...] | _NegativeInfinityType, # local
  87. ],
  88. ],
  89. ):
  90. _regex: ClassVar[re.Pattern[str]] = ...
  91. _version: Final[str]
  92. def __init__(self, /, version: str) -> None: ...
  93. @property
  94. def public(self) -> str: ...
  95. @property
  96. def base_version(self) -> str: ...
  97. @property
  98. def local(self) -> str | None: ...
  99. @property
  100. def is_prerelease(self) -> bool: ...
  101. @property
  102. def is_postrelease(self) -> bool: ...
  103. #
  104. def parse(version: str) -> Version | LegacyVersion: ...