diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2021-07-16 08:34:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-16 08:34:56 (GMT) |
commit | aeaa553d650786afc6e68df1f4813ae1a5b71d05 (patch) | |
tree | de8f5af334a132649dc3f7898b012b8a200c9259 /Objects | |
parent | 919ad537510fdc2c750109e0bc4eceea234324b2 (diff) | |
download | cpython-aeaa553d650786afc6e68df1f4813ae1a5b71d05.zip cpython-aeaa553d650786afc6e68df1f4813ae1a5b71d05.tar.gz cpython-aeaa553d650786afc6e68df1f4813ae1a5b71d05.tar.bz2 |
bpo-44646: Fix the hash of the union type. (#27179)
It no longer depends on the order of arguments.
hash(int | str) == hash(str | int)
Co-authored-by: Jack DeVries <58614260+jdevries3133@users.noreply.github.com>
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/unionobject.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Objects/unionobject.c b/Objects/unionobject.c index 8818cc2..85092e6 100644 --- a/Objects/unionobject.c +++ b/Objects/unionobject.c @@ -36,11 +36,13 @@ static Py_hash_t union_hash(PyObject *self) { unionobject *alias = (unionobject *)self; - Py_hash_t h1 = PyObject_Hash(alias->args); - if (h1 == -1) { - return -1; + PyObject *args = PyFrozenSet_New(alias->args); + if (args == NULL) { + return (Py_hash_t)-1; } - return h1; + Py_hash_t hash = PyObject_Hash(args); + Py_DECREF(args); + return hash; } static int |