Skip to content

Commit 8fce0e3

Browse files
committed
Update staticmethod.rs
1 parent fd45e9e commit 8fce0e3

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

vm/src/builtins/staticmethod.rs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ use crate::{
33
builtins::builtinfunc::PyBuiltinMethod,
44
class::PyClassImpl,
55
function::{FuncArgs, IntoPyNativeFunc},
6-
types::{Callable, Constructor, GetDescriptor},
6+
types::{Callable, Constructor, GetDescriptor, Initializer},
77
Context, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
8+
AsObject
89
};
910

1011
#[pyclass(module = false, name = "staticmethod")]
@@ -62,7 +63,17 @@ impl PyStaticMethod {
6263
}
6364
}
6465

65-
#[pyimpl(with(Callable, GetDescriptor, Constructor), flags(BASETYPE, HAS_DICT))]
66+
impl Initializer for PyStaticMethod {
67+
type Args = PyObjectRef;
68+
69+
fn init(zelf: PyRef<Self>, args: Self::Args, vm: &VirtualMachine) -> PyResult<()> {
70+
zelf.as_object().set_attr("__doc__", args.get_attr("__doc__", vm)?, vm)?;
71+
// zelf.as_object().set_attr("__format__", args.get_attr("__format__", vm)?, vm);
72+
Ok(())
73+
}
74+
}
75+
76+
#[pyimpl(with(Callable, GetDescriptor, Constructor, Initializer), flags(BASETYPE, HAS_DICT))]
6677
impl PyStaticMethod {
6778
#[pyproperty(magic)]
6879
fn isabstractmethod(&self, vm: &VirtualMachine) -> PyObjectRef {
@@ -72,11 +83,46 @@ impl PyStaticMethod {
7283
}
7384
}
7485

86+
#[pyproperty(magic)]
87+
fn func(&self, vm: &VirtualMachine) -> PyObjectRef {
88+
self.callable.clone()
89+
}
90+
91+
#[pyproperty(magic)]
92+
fn wrapped(&self, vm: &VirtualMachine) -> PyObjectRef {
93+
self.callable.clone()
94+
}
95+
7596
#[pyproperty(magic, setter)]
7697
fn set_isabstractmethod(&self, value: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
7798
self.callable.set_attr("__isabstractmethod__", value, vm)?;
7899
Ok(())
79100
}
101+
102+
#[pymethod(magic)]
103+
fn repr(&self, vm: &VirtualMachine) -> PyResult<String> {
104+
Ok(format!("<staticmethod({})>", self.callable.repr(vm)?))
105+
}
106+
107+
#[pyproperty(magic)]
108+
fn module(&self, vm: &VirtualMachine) -> PyResult {
109+
self.callable.get_attr("__module__", vm)
110+
}
111+
112+
#[pyproperty(magic)]
113+
fn name(&self, vm: &VirtualMachine) -> PyResult {
114+
self.callable.get_attr("__name__", vm)
115+
}
116+
117+
#[pyproperty(magic)]
118+
fn qualname(&self, vm: &VirtualMachine) -> PyResult {
119+
self.callable.get_attr("__qualname__", vm)
120+
}
121+
122+
#[pyproperty(magic)]
123+
fn annotations(&self, vm: &VirtualMachine) -> PyResult {
124+
self.callable.get_attr("__annotations__", vm)
125+
}
80126
}
81127

82128
impl Callable for PyStaticMethod {

0 commit comments

Comments
 (0)