Implement Number protocol for PyNone
use super::{PyType, PyTypeRef};
use crate::{
- class::PyClassImpl, convert::ToPyObject, types::Constructor, Context, Py, PyObjectRef,
- PyPayload, PyResult, VirtualMachine,
+ class::PyClassImpl,
+ convert::ToPyObject,
+ protocol::PyNumberMethods,
+ types::{AsNumber, Constructor},
+ Context, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,
};
#[pyclass(module = false, name = "NoneType")]
@@ -39,7 +42,7 @@ impl Constructor for PyNone {
}
}
-#[pyimpl(with(Constructor))]
+#[pyimpl(with(Constructor, AsNumber))]
impl PyNone {
#[pymethod(magic)]
fn repr(&self) -> String {
@@ -52,6 +55,13 @@ impl PyNone {
}
}
+impl AsNumber for PyNone {
+ const AS_NUMBER: PyNumberMethods = PyNumberMethods {
+ boolean: Some(|_number, _vm| Ok(false)),
+ ..PyNumberMethods::NOT_IMPLEMENTED
+ };
+}
+
#[pyclass(module = false, name = "NotImplementedType")]
#[derive(Debug)]
pub struct PyNotImplemented;
