lib.types module
Helper utilities related to Python types.
- assert_never(value)[source]
Raises an AssertionError. This function can be used to achieve exhaustiveness checking with mypy.
REFERENCE: https://hakibenita.com/python-mypy-exhaustive-checking
- Parameters
value (
NoReturn) –- Return type
NoReturn
- literal_to_list(literal)[source]
Convert a typing.Literal into a list.
Examples
>>> from typing import Literal >>> literal_to_list(Literal['a', 'b', 'c']) ['a', 'b', 'c']
>>> literal_to_list(Literal['a', 'b', Literal['c', 'd', Literal['e']]]) ['a', 'b', 'c', 'd', 'e']
>>> literal_to_list(Literal['a', 'b', Literal[1, 2, Literal[None]]]) ['a', 'b', 1, 2, None]
- Parameters
literal (
Any) –- Return type
List[Union[None,bool,bytes,int,str,Enum]]