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:
2536
2536
self .assertEqual (hash (C (4 )), hash ((4 ,)))
2537
2537
self .assertEqual (hash (C (42 )), hash ((42 ,)))
2538
2538
2539
- # TODO: RUSTPYTHON
2540
- @unittest .expectedFailure
2541
2539
def test_hash_no_args (self ):
2542
2540
# Test dataclasses with no hash= argument. This exists to
2543
2541
# 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 {
517
517
}
518
518
519
519
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
+
520
528
let hash = self
521
529
. class ( )
522
530
. mro_find_map ( |cls| cls. slots . hash . load ( ) )
523
- . unwrap ( ) ; // hash always exist
531
+ . unwrap ( ) ;
532
+
524
533
hash ( self , vm)
525
534
}
526
535
You can’t perform that action at this time.
0 commit comments