File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed
Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -2536,8 +2536,6 @@ class C:
25362536 self .assertEqual (hash (C (4 )), hash ((4 ,)))
25372537 self .assertEqual (hash (C (42 )), hash ((42 ,)))
25382538
2539- # TODO: RUSTPYTHON
2540- @unittest .expectedFailure
25412539 def test_hash_no_args (self ):
25422540 # Test dataclasses with no hash= argument. This exists to
25432541 # make sure that if the @dataclass parameter name is changed
Original file line number Diff line number Diff line change @@ -517,10 +517,19 @@ impl PyObject {
517517 }
518518
519519 pub fn hash ( & self , vm : & VirtualMachine ) -> PyResult < PyHash > {
520+ let hash = self . get_class_attr ( identifier ! ( vm, __hash__) ) . unwrap ( ) ;
521+ if vm. is_none ( & hash) {
522+ return Err ( vm. new_exception_msg (
523+ vm. ctx . exceptions . type_error . to_owned ( ) ,
524+ format ! ( "unhashable type: '{}'" , self . class( ) . name( ) ) ,
525+ ) ) ;
526+ }
527+
520528 let hash = self
521529 . class ( )
522530 . mro_find_map ( |cls| cls. slots . hash . load ( ) )
523- . unwrap ( ) ; // hash always exist
531+ . unwrap ( ) ;
532+
524533 hash ( self , vm)
525534 }
526535
You can’t perform that action at this time.
0 commit comments