Dominik V. added the comment:
Thinking more about it, I came to realize that it's not the Union that sits at the root of this behavior, but rather the caching performed by generic types in general. So if we consider
```
L1 = List[Union[int, str]]
L2 = List[Union[str, int]]
```
then `get_args(L1)[0] is get_args(L2)[0]` and so `get_args` has no influence on the order of arguments of the Union objects (they are already the same for L1 and L2).
So I think it would be more accurate to add the following sentence instead:
If `X` is a generic type, the returned objects `(Y, Z, ...)` might not be identical to the ones used in the form `X[Y, Z, ...]` due to type caching.
Everything else follows from there (including flattening of nested Unions).
----------
_______________________________________
Python tracker
https://bugs.python.org/issue42317
_______________________________________