@@ -765,6 +765,13 @@ def Union(self, parameters):
765765
766766 assert Union[Union[int, str], float] == Union[int, str, float]
767767
768+ However, this does not apply to unions referenced through a type
769+ alias, to avoid forcing evaluation of the underlying
770+ TypeAliasType::
771+
772+ type A = Union[int, str]
773+ assert Union[A, float] != Union[int, str, float]
774+
768775 - Unions of a single argument vanish, e.g.::
769776
770777 assert Union[int] == int # The constructor actually returns int
@@ -830,6 +837,33 @@ def open_helper(file: str, mode: MODE) -> str:
830837 Literal[...] cannot be subclassed. At runtime, an arbitrary value
831838 is allowed as type argument to Literal[...], but type checkers may
832839 impose restrictions.
840+
841+ Literal is very similar to Union, the main difference is that its
842+ arguments are literal values instead of types:
843+
844+ - The arguments must be literal values and there must be at least one.
845+
846+ - Nested Literal types are flattened, e.g.::
847+
848+ assert Literal[Literal[1, 2], 3] == Literal[1, 2, 3]
849+
850+ However, this does not apply to Literal types referenced through a type
851+ alias, to avoid forcing evaluation of the underlying TypeAliasType::
852+
853+ type A = Literal[1, 2]
854+ assert Literal[A, 3] != Literal[1, 2, 3]
855+
856+ - Redundant arguments are skipped, e.g.::
857+
858+ assert Union[1, 2, 1] == Union[1, 2]
859+
860+ - When comparing literals, the argument order is ignored, e.g.::
861+
862+ assert Literal[1, 2] == Literal[2, 1]
863+
864+ - You cannot subclass or instantiate a Literal.
865+
866+ - You cannot write Literal[X][Y].
833867 """
834868 # There is no '_type_check' call because arguments to Literal[...] are
835869 # values, not types.
0 commit comments