Use new style for PyStaticMethod impl

This commit is contained in:
Daniel Alley
2019-10-04 00:33:33 -04:00
parent df6acaf163
commit fb04771cad

View File

@@ -1,7 +1,8 @@
use super::objtype::PyClassRef;
use crate::pyobject::{PyContext, PyObjectRef, PyRef, PyResult, PyValue};
use crate::pyobject::{PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue};
use crate::vm::VirtualMachine;
#[pyclass(name = "staticmethod")]
#[derive(Clone, Debug)]
pub struct PyStaticMethod {
pub callable: PyObjectRef,
@@ -14,8 +15,10 @@ impl PyValue for PyStaticMethod {
}
}
#[pyimpl]
impl PyStaticMethodRef {
fn new(
#[pyslot(new)]
fn tp_new(
cls: PyClassRef,
callable: PyObjectRef,
vm: &VirtualMachine,
@@ -26,15 +29,12 @@ impl PyStaticMethodRef {
.into_ref_with_type(vm, cls)
}
#[pymethod(name = "__get__")]
fn get(self, _inst: PyObjectRef, _owner: PyObjectRef, _vm: &VirtualMachine) -> PyResult {
Ok(self.callable.clone())
}
}
pub fn init(context: &PyContext) {
let staticmethod_type = &context.types.staticmethod_type;
extend_class!(context, staticmethod_type, {
"__get__" => context.new_rustfunc(PyStaticMethodRef::get),
(slot new) => PyStaticMethodRef::new,
});
PyStaticMethodRef::extend_class(context, &context.types.staticmethod_type);
}