|
72 | 72 |
|
73 | 73 |
|
74 | 74 | def assert_never(inp: NoReturn, raise_error: bool = True, exc: Union[Exception, None] = None) -> None:
|
75 |
| - """For use in exhaustive checking of literal or Enum in if/else chain. |
| 75 | + """For use in exhaustive checking of a literal or enum in if/else chains. |
76 | 76 |
|
77 |
| - Should only be reached if all members not handled OR attempt to pass non-members through chain. |
| 77 | + A call to this function should only be reached if not all members are handled, or if |
| 78 | + an attempt is made to pass non-members through the chain. |
78 | 79 |
|
79 |
| - If all members handled, type is Empty. Otherwise, will cause mypy error. |
| 80 | + :param inp: |
| 81 | + If all members are handled, the argument for `inp` will have the |
| 82 | + :class:`~typing.Never`/:class:`~typing.NoReturn` type. Otherwise, the type will |
| 83 | + mismatch and cause a mypy error. |
80 | 84 |
|
81 |
| - If non-members given, should cause mypy error at variable creation. |
| 85 | + :param raise_error: |
| 86 | + If ``True``, will also raise :class:`ValueError` with a general "unhandled |
| 87 | + literal" message, or the exception object passed as `exc`. |
82 | 88 |
|
83 |
| - If raise_error is True, will also raise AssertionError or the Exception passed to exc. |
| 89 | + :param exc: |
| 90 | + It not ``None``, this should be an already-constructed exception object, to be |
| 91 | + raised if `raise_error` is ``True``. |
84 | 92 | """
|
85 | 93 | if raise_error:
|
86 | 94 | if exc is None:
|
87 |
| - raise ValueError(f"An unhandled Literal ({inp}) in an if/else chain was found") |
| 95 | + raise ValueError(f"An unhandled literal ({inp!r}) in an if/else chain was found") |
88 | 96 | else:
|
89 | 97 | raise exc
|
90 | 98 |
|
|
0 commit comments