Add float.__hash__

This commit is contained in:
Jeong YunWon
2019-05-09 07:01:39 +09:00
parent 72043dac99
commit 2c77dc208f
5 changed files with 91 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ use super::objstr;
use super::objtype;
use crate::function::OptionalArg;
use crate::obj::objtype::PyClassRef;
use crate::pyhash;
use crate::pyobject::{
IdProtocol, IntoPyObject, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue,
TypeProtocol,
@@ -429,6 +430,11 @@ impl PyFloat {
zelf
}
#[pymethod(name = "__hash__")]
fn hash(&self, _vm: &VirtualMachine) -> pyhash::PyHash {
pyhash::hash_float(self.value)
}
#[pyproperty(name = "real")]
fn real(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyFloatRef {
zelf