From 1c5b9c9e0382a4bd3e2b40b7745798f8f5370241 Mon Sep 17 00:00:00 2001 From: Lee Dogeon Date: Fri, 15 Jul 2022 07:41:15 +0900 Subject: [PATCH 1/2] Correct union hash https://github.com/RustPython/RustPython/issues/3851 --- vm/src/builtins/union.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/vm/src/builtins/union.rs b/vm/src/builtins/union.rs index d43fbc10b..a47d058c1 100644 --- a/vm/src/builtins/union.rs +++ b/vm/src/builtins/union.rs @@ -6,7 +6,7 @@ use crate::{ convert::ToPyObject, function::PyComparisonValue, protocol::PyMappingMethods, - types::{AsMapping, Comparable, GetAttr, Hashable, Iterable, PyComparisonOp}, + types::{AsMapping, Comparable, GetAttr, Hashable, PyComparisonOp}, AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, }; @@ -264,8 +264,7 @@ impl Comparable for PyUnion { impl Hashable for PyUnion { #[inline] fn hash(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { - let it = PyTuple::iter(zelf.args.clone(), vm); - let set = PyFrozenSet::from_iter(vm, it)?; + let set = PyFrozenSet::from_iter(vm, zelf.args.into_iter().cloned())?; PyFrozenSet::hash(&set.into_ref(vm), vm) } } From 5658a6b069fdcead63e189c3f59f20910de2a1a6 Mon Sep 17 00:00:00 2001 From: moreal Date: Tue, 2 Aug 2022 12:16:18 +0900 Subject: [PATCH 2/2] Unmark fixed tests --- Lib/test/test_types.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index 9ba6a077e..053318b5d 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -703,8 +703,6 @@ class UnionTests(unittest.TestCase): y.__args__ = [str, int] self.assertEqual(x, y) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_hash(self): self.assertEqual(hash(int | str), hash(str | int)) self.assertEqual(hash(int | str), hash(typing.Union[int, str]))