_pep440.pyi 3.8 KB

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