9
9
import sys
10
10
from argparse import SUPPRESS , Action , ArgumentDefaultsHelpFormatter , ArgumentError , ArgumentParser , Namespace
11
11
from pathlib import Path
12
- from typing import TYPE_CHECKING , Any , Callable , Dict , List , Literal , Optional , Sequence , Tuple , Type , TypeVar , cast
12
+ from types import UnionType
13
+ from typing import TYPE_CHECKING , Any , Literal , TypeVar , cast
13
14
14
15
from colorama import Fore
15
16
26
27
from typing_extensions import Self
27
28
28
29
if TYPE_CHECKING :
30
+ from collections .abc import Callable , Sequence
31
+
29
32
from tox .session .state import State
30
33
31
34
@@ -64,7 +67,7 @@ def get_type(action: Action) -> type[Any]:
64
67
of_type : type [Any ] | None = getattr (action , "of_type" , None )
65
68
if of_type is None :
66
69
if isinstance (action , argparse ._AppendAction ): # noqa: SLF001
67
- of_type = List [action .type ] # type: ignore[name-defined]
70
+ of_type = list [action .type ] # type: ignore[name-defined]
68
71
elif isinstance (action , argparse ._StoreAction ) and action .choices : # noqa: SLF001
69
72
loc = locals ()
70
73
loc ["Literal" ] = Literal
@@ -135,7 +138,7 @@ def is_colored(self) -> bool:
135
138
exit_and_dump_after : int
136
139
137
140
138
- ArgumentArgs = Tuple [ Tuple [str , ...], Optional [ Type [ Any ]], Dict [str , Any ]]
141
+ ArgumentArgs = tuple [ tuple [str , ...], type [ Any ] | UnionType | None , dict [str , Any ]]
139
142
140
143
141
144
class ToxParser (ArgumentParserWithEnvAndConfig ):
@@ -230,7 +233,7 @@ def __call__(
230
233
help = "set PYTHONHASHSEED to SEED before running commands. Defaults to a random integer in the range "
231
234
"[1, 4294967295] ([1, 1024] on Windows). Passing 'notset' suppresses this behavior." ,
232
235
action = SeedAction ,
233
- of_type = Optional [ int ], # type: ignore[arg-type]
236
+ of_type = int | None ,
234
237
default = hashseed_default ,
235
238
dest = "hash_seed" ,
236
239
)
@@ -239,7 +242,7 @@ def __call__(
239
242
dest = "discover" ,
240
243
nargs = "+" ,
241
244
metavar = "path" ,
242
- of_type = List [str ],
245
+ of_type = list [str ],
243
246
help = "for Python discovery first try these Python executables" ,
244
247
default = [],
245
248
)
@@ -280,7 +283,7 @@ def add_argument(*a_args: str, of_type: type[Any] | None = None, **a_kwargs: Any
280
283
self ._groups .append ((args , kwargs , excl ))
281
284
return result
282
285
283
- def add_argument (self , * args : str , of_type : type [Any ] | None = None , ** kwargs : Any ) -> Action :
286
+ def add_argument (self , * args : str , of_type : type [Any ] | UnionType | None = None , ** kwargs : Any ) -> Action :
284
287
result = super ().add_argument (* args , ** kwargs )
285
288
if self .of_cmd is None and result .dest != "help" :
286
289
self ._arguments .append ((args , of_type , kwargs ))
@@ -403,7 +406,7 @@ def add_core_arguments(parser: ArgumentParser) -> None:
403
406
metavar = "file" ,
404
407
default = None ,
405
408
type = Path ,
406
- of_type = Optional [ Path ] ,
409
+ of_type = Path | None ,
407
410
help = "configuration file/folder for tox (if not specified will discover one)" ,
408
411
)
409
412
parser .add_argument (
@@ -412,7 +415,7 @@ def add_core_arguments(parser: ArgumentParser) -> None:
412
415
metavar = "dir" ,
413
416
default = None ,
414
417
type = Path ,
415
- of_type = Optional [ Path ] ,
418
+ of_type = Path | None ,
416
419
help = "tox working directory (if not specified will be the folder of the config file)" ,
417
420
)
418
421
parser .add_argument (
@@ -421,7 +424,7 @@ def add_core_arguments(parser: ArgumentParser) -> None:
421
424
metavar = "dir" ,
422
425
default = None ,
423
426
type = Path ,
424
- of_type = Optional [ Path ] ,
427
+ of_type = Path | None ,
425
428
help = "project root directory (if not specified will be the folder of the config file)" ,
426
429
)
427
430
0 commit comments