diff --git a/Lib/test/test_dataclasses.py b/Lib/test/test_dataclasses.py index 484ff7def9..9f74d9d1e4 100644 --- a/Lib/test/test_dataclasses.py +++ b/Lib/test/test_dataclasses.py @@ -2536,8 +2536,6 @@ class TestHash(unittest.TestCase): self.assertEqual(hash(C(4)), hash((4,))) self.assertEqual(hash(C(42)), hash((42,))) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_hash_no_args(self): # Test dataclasses with no hash= argument. This exists to # make sure that if the @dataclass parameter name is changed diff --git a/vm/src/protocol/object.rs b/vm/src/protocol/object.rs index 6764fcabd8..8aec33db08 100644 --- a/vm/src/protocol/object.rs +++ b/vm/src/protocol/object.rs @@ -517,10 +517,19 @@ impl PyObject { } pub fn hash(&self, vm: &VirtualMachine) -> PyResult { + let hash = self.get_class_attr(identifier!(vm, __hash__)).unwrap(); + if vm.is_none(&hash) { + return Err(vm.new_exception_msg( + vm.ctx.exceptions.type_error.to_owned(), + format!("unhashable type: '{}'", self.class().name()), + )); + } + let hash = self .class() .mro_find_map(|cls| cls.slots.hash.load()) - .unwrap(); // hash always exist + .unwrap(); + hash(self, vm) }