4
4
5
5
import os
6
6
import sys
7
- from typing import (Callable , Dict , NoReturn , Tuple , Union , Any , Iterator , # noqa: F401
7
+ from typing import (Callable , Dict , NoReturn , Sequence , Tuple , Union , Any , Iterator , # noqa: F401
8
8
NamedTuple , TYPE_CHECKING , TypeVar ) # noqa: F401
9
9
10
10
if TYPE_CHECKING :
37
37
Tree_ish = Union ['Commit' , 'Tree' ]
38
38
Commit_ish = Union ['Commit' , 'TagObject' , 'Blob' , 'Tree' ]
39
39
40
+ # Config_levels ---------------------------------------------------------
41
+
40
42
Lit_config_levels = Literal ['system' , 'global' , 'user' , 'repository' ]
41
43
42
44
@@ -47,12 +49,25 @@ def is_config_level(inp: str) -> TypeGuard[Lit_config_levels]:
47
49
48
50
ConfigLevels_Tup = Tuple [Literal ['system' ], Literal ['user' ], Literal ['global' ], Literal ['repository' ]]
49
51
52
+ #-----------------------------------------------------------------------------------
53
+
54
+
55
+ def assert_never (inp : NoReturn , raise_error : bool = True , exc : Union [Exception , None ] = None ) -> None :
56
+ """For use in exhaustive checking of literal or Enum in if/else chain.
57
+ Should only be reached if all memebers not handled OR attempt to pass non-members through chain.
58
+
59
+ If all members handled, type is Empty. Otherwise, will cause mypy error.
60
+ If non-members given, should cause mypy error at variable creation.
50
61
51
- def assert_never (inp : NoReturn , exc : Union [Exception , None ] = None ) -> NoReturn :
52
- if exc is None :
53
- assert False , f"An unhandled Literal ({ inp } ) in an if/else chain was found"
62
+ If raise_error is True, will also raise AssertionError or the Exception passed to exc.
63
+ """
64
+ if raise_error :
65
+ if exc is None :
66
+ raise ValueError (f"An unhandled Literal ({ inp } ) in an if/else chain was found" )
67
+ else :
68
+ raise exc
54
69
else :
55
- raise exc
70
+ pass
56
71
57
72
58
73
class Files_TD (TypedDict ):
0 commit comments