4
4
import sys
5
5
import warnings
6
6
from itertools import zip_longest
7
- from typing import TYPE_CHECKING , Any , ClassVar , Protocol , Type , cast , runtime_checkable
7
+ from typing import (
8
+ TYPE_CHECKING ,
9
+ Any ,
10
+ ClassVar ,
11
+ Literal ,
12
+ Protocol ,
13
+ Type ,
14
+ cast ,
15
+ runtime_checkable ,
16
+ )
8
17
9
18
import importlib_metadata as metadata
10
19
from packaging .version import InvalidVersion # noqa: F401: Rexpose the common exception
28
37
from typing import Self
29
38
30
39
40
+ Increment : TypeAlias = Literal ["MAJOR" , "MINOR" , "PATCH" ]
41
+ Prerelease : TypeAlias = Literal ["alpha" , "beta" , "rc" ]
31
42
DEFAULT_VERSION_PARSER = r"v?(?P<version>([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?(\w+)?)"
32
43
33
44
@@ -113,8 +124,8 @@ def __ne__(self, other: object) -> bool:
113
124
114
125
def bump (
115
126
self ,
116
- increment : str ,
117
- prerelease : str | None = None ,
127
+ increment : Increment | None ,
128
+ prerelease : Prerelease | None = None ,
118
129
prerelease_offset : int = 0 ,
119
130
devrelease : int | None = None ,
120
131
is_local_version : bool = False ,
@@ -203,7 +214,7 @@ def generate_build_metadata(self, build_metadata: str | None) -> str:
203
214
204
215
return f"+{ build_metadata } "
205
216
206
- def increment_base (self , increment : str | None = None ) -> str :
217
+ def increment_base (self , increment : Increment | None = None ) -> str :
207
218
prev_release = list (self .release )
208
219
increments = [MAJOR , MINOR , PATCH ]
209
220
base = dict (zip_longest (increments , prev_release , fillvalue = 0 ))
@@ -222,8 +233,8 @@ def increment_base(self, increment: str | None = None) -> str:
222
233
223
234
def bump (
224
235
self ,
225
- increment : str ,
226
- prerelease : str | None = None ,
236
+ increment : Increment | None ,
237
+ prerelease : Prerelease | None = None ,
227
238
prerelease_offset : int = 0 ,
228
239
devrelease : int | None = None ,
229
240
is_local_version : bool = False ,
0 commit comments