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 kj
Recipients Dominik V., docs@python, gvanrossum, kj, levkivskyi
Date 2020-11-11.14:01:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
You're right, currently this happens for 2 reasons:

1. _SpecialGenericAlias (used by List), caches its __getitem__. (As you already pointed out :) )

2. _UnionGenericAlias (Union)'s __hash__ is `hash(frozenset(self.__args__))`. i.e. Unions with different args orders but same unique args produce the same hash result. Causing the same cache hit.

I find it mildly sad however that:

>>> get_args(Union[int, str])
[int, str]

>>> get_args(Union[str, int])
[str, int]

Which is slightly inconsistent with its behavior when nested in List. I don't think there's an easy way to fix this without breaking the cache (and also it makes sense that Unions' args aren't order dependent). So I'm all for updating the docs with your addition (slightly edited):

> If `X` is a `Union`, the order of `(Y, Z, ...)` may be different from the order of the original arguments `[Y, Z, ...]`.
Date User Action Args
2020-11-11 14:01:02kjsetrecipients: + kj, gvanrossum, docs@python, levkivskyi, Dominik V.
2020-11-11 14:01:02kjsetmessageid: <>
2020-11-11 14:01:02kjlinkissue42317 messages
2020-11-11 14:01:01kjcreate