mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
Merge pull request #2712 from DimitrisJim/notimplemented_behaviour
Add new and bool for NotImplemented.
This commit is contained in:
@@ -1561,8 +1561,6 @@ class BuiltinTest(unittest.TestCase):
|
||||
self.assertRaises(ValueError, x.translate, b"1", 1)
|
||||
self.assertRaises(TypeError, x.translate, b"1"*256, 1)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_construct_singletons(self):
|
||||
for const in None, Ellipsis, NotImplemented:
|
||||
tp = type(const)
|
||||
|
||||
@@ -61,6 +61,19 @@ impl PyValue for PyNotImplemented {
|
||||
|
||||
#[pyimpl]
|
||||
impl PyNotImplemented {
|
||||
#[pyslot]
|
||||
fn tp_new(_: PyTypeRef, vm: &VirtualMachine) -> PyRef<Self> {
|
||||
vm.ctx.not_implemented.clone()
|
||||
}
|
||||
|
||||
// TODO: As per https://bugs.python.org/issue35712, using NotImplemented
|
||||
// in boolean contexts will need to raise a DeprecationWarning in 3.9
|
||||
// and, eventually, a TypeError.
|
||||
#[pymethod(magic)]
|
||||
fn bool(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[pymethod(magic)]
|
||||
fn repr(&self) -> String {
|
||||
"NotImplemented".to_owned()
|
||||
|
||||
Reference in New Issue
Block a user