This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Dominik V.
Recipients Dominik V.
Date 2020-11-13.14:11:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
[PEP 586]( 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]

Compare with the equivalent form:

    >>> Union[Literal[1], Literal[2]] == Union[Literal[2], Literal[1]]

In addition to that, the PEP specifies that nested Literals should be equivalent to the flattened version ( 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]

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:55Dominik V.setrecipients: + Dominik V.
2020-11-13 14:11:55Dominik V.setmessageid: <>
2020-11-13 14:11:55Dominik V.linkissue42345 messages
2020-11-13 14:11:55Dominik V.create