File tree 3 files changed +16
-2
lines changed
3 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -86,6 +86,11 @@ pub fn hash_pointer(value: usize) -> PyHash {
86
86
hash as _
87
87
}
88
88
89
+ #[ inline]
90
+ pub fn hash_integer < T : num_traits:: PrimInt > ( data : T ) -> PyHash {
91
+ fix_sentinel ( mod_int ( data. to_i64 ( ) . unwrap ( ) ) )
92
+ }
93
+
89
94
#[ inline]
90
95
pub fn hash_float ( value : f64 ) -> Option < PyHash > {
91
96
// cpython _Py_HashDouble
Original file line number Diff line number Diff line change 1
1
class MyObject :
2
2
pass
3
3
4
+
4
5
assert not MyObject () == MyObject ()
5
6
assert MyObject () != MyObject ()
6
7
myobj = MyObject ()
@@ -24,3 +25,10 @@ class MyObject:
24
25
assert not hasattr (obj , 'a' )
25
26
obj .__dict__ = {'a' : 1 }
26
27
assert obj .a == 1
28
+
29
+ # Value inside the formatter goes through a different path of resolution.
30
+ # Check that it still works all the same
31
+ d = {
32
+ 0 : "ab" ,
33
+ }
34
+ assert "ab ab" == "{k[0]} {vv}" .format (k = d , vv = d [0 ])
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ use crate::{
17
17
object:: { Traverse , TraverseFn } ,
18
18
} ;
19
19
use num_traits:: ToPrimitive ;
20
+ use rustpython_common:: hash:: hash_integer;
20
21
use std:: { fmt, mem:: size_of, ops:: ControlFlow } ;
21
22
22
23
// HashIndex is intended to be same size with hash::PyHash
@@ -993,8 +994,8 @@ impl DictKey for usize {
993
994
* self
994
995
}
995
996
996
- fn key_hash ( & self , vm : & VirtualMachine ) -> PyResult < HashValue > {
997
- Ok ( vm . state . hash_secret . hash_value ( self ) )
997
+ fn key_hash ( & self , _vm : & VirtualMachine ) -> PyResult < HashValue > {
998
+ Ok ( hash_integer ( * self ) )
998
999
}
999
1000
1000
1001
fn key_is ( & self , _other : & PyObject ) -> bool {
You can’t perform that action at this time.
0 commit comments