Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Implement Number protocol for PyNone
  • Loading branch information
hy-kiera committed Jul 15, 2022
commit 47587d1bb4132831ea8f4ad2df5fed0a6eed4060
13 changes: 10 additions & 3 deletions vm/src/builtins/singletons.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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,
types::Constructor, Context, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also group type traits

types::{AsNumber, Constructor}

};

#[pyclass(module = false, name = "NoneType")]
Expand Down Expand Up @@ -39,7 +39,7 @@ impl Constructor for PyNone {
}
}

#[pyimpl(with(Constructor))]
#[pyimpl(with(Constructor, AsNumber))]
impl PyNone {
#[pymethod(magic)]
fn repr(&self) -> String {
Expand All @@ -52,6 +52,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;
Expand Down