◐ Shell
clean mode source ↗

Message 397564 - Python tracker

It is a difference with typing.Union which can cause confusion. If the union type is like a tuple and we leave a 1-type union, why do we bother with deduplication? Why int | str | int is collapsed into int | str?

Also it complicates the comparison implementation and produces surprising exceptions:

>>> int | str == {}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'dict'

Also it breaks one of fundamental properties -- equal objects should have equal hashes.

>>> (int | int) == int
True
>>> hash(int | int) == hash(int)
False