forked from Rust-related/RustPython
Fix hash's error message when hash method is None (#4161)
This commit is contained in:
2
Lib/test/test_dataclasses.py
vendored
2
Lib/test/test_dataclasses.py
vendored
@@ -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
|
||||
|
||||
@@ -517,10 +517,19 @@ impl PyObject {
|
||||
}
|
||||
|
||||
pub fn hash(&self, vm: &VirtualMachine) -> PyResult<PyHash> {
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user