diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py index 73e5cab2b..8b61f4feb 100644 --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -582,8 +582,6 @@ class GeneralFloatCases(unittest.TestCase): self.assertEqual(hash(float('inf')), sys.hash_info.inf) self.assertEqual(hash(float('-inf')), -sys.hash_info.inf) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_hash_nan(self): value = float('nan') self.assertEqual(hash(value), object.__hash__(value)) diff --git a/vm/src/builtins/float.rs b/vm/src/builtins/float.rs index ee4837090..0e047d499 100644 --- a/vm/src/builtins/float.rs +++ b/vm/src/builtins/float.rs @@ -539,7 +539,11 @@ impl Comparable for PyFloat { impl Hashable for PyFloat { #[inline] fn hash(zelf: &crate::Py, _vm: &VirtualMachine) -> PyResult { - Ok(hash::hash_float(zelf.to_f64())) + if zelf.to_f64().is_nan() { + Ok(zelf.get_id() as hash::PyHash) + } else { + Ok(hash::hash_float(zelf.to_f64())) + } } }