Skip to content

Commit 10327b5

Browse files
authored
Implement Number protocol for PyNone (#3880)
1 parent fa40a13 commit 10327b5

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

vm/src/builtins/singletons.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use super::{PyType, PyTypeRef};
22
use crate::{
3-
class::PyClassImpl, convert::ToPyObject, types::Constructor, Context, Py, PyObjectRef,
4-
PyPayload, PyResult, VirtualMachine,
3+
class::PyClassImpl,
4+
convert::ToPyObject,
5+
protocol::PyNumberMethods,
6+
types::{AsNumber, Constructor},
7+
Context, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,
58
};
69

710
#[pyclass(module = false, name = "NoneType")]
@@ -39,7 +42,7 @@ impl Constructor for PyNone {
3942
}
4043
}
4144

42-
#[pyimpl(with(Constructor))]
45+
#[pyimpl(with(Constructor, AsNumber))]
4346
impl PyNone {
4447
#[pymethod(magic)]
4548
fn repr(&self) -> String {
@@ -52,6 +55,13 @@ impl PyNone {
5255
}
5356
}
5457

58+
impl AsNumber for PyNone {
59+
const AS_NUMBER: PyNumberMethods = PyNumberMethods {
60+
boolean: Some(|_number, _vm| Ok(false)),
61+
..PyNumberMethods::NOT_IMPLEMENTED
62+
};
63+
}
64+
5565
#[pyclass(module = false, name = "NotImplementedType")]
5666
#[derive(Debug)]
5767
pub struct PyNotImplemented;

0 commit comments

Comments
 (0)