Closed intgr closed 4 years ago
I'm surprised Python doesn't automatically flatten the tree, like it does with nested Union
s.
Yep, doesn't work like that
In [1]: from typing_extensions import Literal
In [2]: Literal[Literal['a'], 'b'].__args__
Out[2]: (typing_extensions.Literal['a'], 'b')
In [6]: Literal[Literal['a']]
Out[6]: typing_extensions.Literal[typing_extensions.Literal['a']]
PS: Any rough timeline for merging this and the next release? (#8 is not that important)
I've merged it and will create a new release in the next hour or so. I'll take a look at #8 when I've a bit more time somewhere later this week.
Turns out there was a bug in #5. Whilst working on #8 it occurred to me that I left this case unhandled.
The set of allowed types in Literal[] is quite limited, but the case of other nested Literal[]s was not properly handled.
For more details: https://www.python.org/dev/peps/pep-0586/#legal-parameters-for-literal-at-type-check-time