Message380888
[PEP 586](https://www.python.org/dev/peps/pep-0586/#shortening-unions-of-literals) specifies that
Literal[v1, v2, v3]
is equivalent to
Union[Literal[v1], Literal[v2], Literal[v3]]
Since the equality of Unions doesn't take into account the order of arguments, Literals parametrized with multiple arguments should not be order dependent either. However they seem to:
>>> Literal[1, 2] == Literal[2, 1]
False
Compare with the equivalent form:
>>> Union[Literal[1], Literal[2]] == Union[Literal[2], Literal[1]]
True
In addition to that, the PEP specifies that nested Literals should be equivalent to the flattened version (https://www.python.org/dev/peps/pep-0586/#legal-parameters-for-literal-at-type-check-time). This section is titled "Legal parameters for Literal at type check time" but since the PEP doesn't specify runtime behavior differently, I think it makes sense to assume it is the same. It seems to be different though:
>>> Literal[Literal[1, 2], 3]
typing.Literal[typing.Literal[1, 2], 3]
>>> Literal[Literal[1, 2], 3] == Literal[1, 2, 3]
False
Also the flattening follows from the above definition `Literal[v1, v2, v3] == Union[Literal[v1], Literal[v2], Literal[v3]]` and the fact that Unions are flattened. |
|
Date |
User |
Action |
Args |
2020-11-13 14:11:55 | Dominik V. | set | recipients:
+ Dominik V. |
2020-11-13 14:11:55 | Dominik V. | set | messageid: <1605276715.65.0.853257843244.issue42345@roundup.psfhosted.org> |
2020-11-13 14:11:55 | Dominik V. | link | issue42345 messages |
2020-11-13 14:11:55 | Dominik V. | create | |
|