You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you create Literal annotation and then create Literal[True] annotation, in the second case you will actually get Literal instead. This is happening because typing performs caching of the outcome of parameterizing generics and hash(True) is equal to hash(1). I think this behavior is incorrect and may lead to unexpected results.
Why is this inaccuracy important?
Consider the following example:
If we look at func.__annotations__["arg"], we will see Literal[1, 'abc']. According to the new annotation, we can pass the value 1 to func, and this will lead to an attribute error, as you've already understood. Thus, proper runtime type checking cannot be performed.