12
12
import subprocess
13
13
import sys
14
14
import tokenize
15
- from types import UnionType
16
15
from typing import (
17
16
Any ,
18
17
Callable ,
27
26
from typing_extensions import Literal
28
27
from typing_inspect import get_args , get_origin as typing_inspect_get_origin
29
28
29
+ if sys .version_info >= (3 , 10 ):
30
+ from types import UnionType
30
31
31
32
NO_CHANGES_STATUS = """nothing to commit, working tree clean"""
32
33
PRIMITIVES = (str , int , float , bool )
@@ -256,7 +257,7 @@ def get_literals(literal: Literal, variable: str) -> Tuple[Callable[[str], Any],
256
257
literals = list (get_args (literal ))
257
258
258
259
if not all (isinstance (literal , PRIMITIVES ) for literal in literals ):
259
- raise ValueError (
260
+ raise ArgumentTypeError (
260
261
f'The type for variable "{ variable } " contains a literal'
261
262
f'of a non-primitive type e.g. (str, int, float, bool).\n '
262
263
f'Currently only primitive-typed literals are supported.'
@@ -265,7 +266,7 @@ def get_literals(literal: Literal, variable: str) -> Tuple[Callable[[str], Any],
265
266
str_to_literal = {str (literal ): literal for literal in literals }
266
267
267
268
if len (literals ) != len (str_to_literal ):
268
- raise ValueError ('All literals must have unique string representations' )
269
+ raise ArgumentTypeError ('All literals must have unique string representations' )
269
270
270
271
def var_type (arg : str ) -> Any :
271
272
return str_to_literal .get (arg , arg )
@@ -404,7 +405,7 @@ def as_python_object(dct: Any) -> Any:
404
405
return UnpicklableObject ()
405
406
406
407
else :
407
- raise ValueError (f'Special type "{ _type } " not supported for JSON loading.' )
408
+ raise ArgumentTypeError (f'Special type "{ _type } " not supported for JSON loading.' )
408
409
409
410
return dct
410
411
@@ -482,7 +483,7 @@ def get_origin(tp: Any) -> Any:
482
483
if origin is None :
483
484
origin = tp
484
485
485
- if isinstance (origin , UnionType ):
486
+ if sys . version_info >= ( 3 , 10 ) and isinstance (origin , UnionType ):
486
487
origin = UnionType
487
488
488
489
return origin
0 commit comments