Use typing.getargs()
to get a list of typing.Literal[…]
values
Here’s a handy little function I discovered while reading the docs for the typing
module:
>>> import typing
>>> Color = typing.Literal['red', 'green', 'blue']
>>> typing.get_args(Color)
('red', 'green', 'blue')
I use typing.Literal
in a bunch of places, and being able to iterate through the values like this could be really helpful.