classification
Title: hash() of the unity type is not consistent with equality
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.11, Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Jelle Zijlstra, gvanrossum, kj, lukasz.langa, miss-islington, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2021-07-15 16:28 by serhiy.storchaka, last changed 2021-07-16 09:03 by lukasz.langa. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 27179 merged serhiy.storchaka, 2021-07-16 07:05
PR 27180 merged miss-islington, 2021-07-16 08:35
Messages (3)
msg397567 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-07-15 16:28
There is a rule: equal hashable objects should have the same hash. The unity type violates it.

>>> x = int | str
>>> y = str | int
>>> x == y
True
>>> hash(x) == hash(y)
False

And hashes of equal unity type and typing.Union are different too.

>>> import typing
>>> z = typing.Union[int, str]
>>> x == z
True
>>> hash(x) == hash(z)
False

There is also a problem with a single type (see issue44636).
msg397603 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-07-16 08:35
New changeset aeaa553d650786afc6e68df1f4813ae1a5b71d05 by Serhiy Storchaka in branch 'main':
bpo-44646: Fix the hash of the union type. (#27179)
https://github.com/python/cpython/commit/aeaa553d650786afc6e68df1f4813ae1a5b71d05
msg397604 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-07-16 09:03
New changeset 705988056e028bab3dbc5cff3671a8ddefc88ec7 by Miss Islington (bot) in branch '3.10':
bpo-44646: Fix the hash of the union type. (GH-27179) (#27180)
https://github.com/python/cpython/commit/705988056e028bab3dbc5cff3671a8ddefc88ec7
History
Date User Action Args
2021-07-16 09:03:39lukasz.langasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-07-16 09:03:16lukasz.langasetmessages: + msg397604
2021-07-16 08:35:46miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request25717
2021-07-16 08:35:31lukasz.langasetnosy: + lukasz.langa
messages: + msg397603
2021-07-16 07:05:27serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request25716
2021-07-16 05:52:53Jelle Zijlstrasetnosy: + Jelle Zijlstra
2021-07-15 16:28:49serhiy.storchakacreate