Skip to content

Commit c3d1417

Browse files
committed
Add descriptors to @classmethod and @staticmethod
1 parent e5bf112 commit c3d1417

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

vm/src/builtins/classmethod.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,36 @@ impl PyClassMethod {
100100
self.callable.lock().clone()
101101
}
102102

103+
#[pyproperty(magic)]
104+
fn wrapped(&self) -> PyObjectRef {
105+
self.callable.clone()
106+
}
107+
108+
#[pyproperty(magic)]
109+
fn module(&self, vm: &VirtualMachine) -> PyResult {
110+
self.callable.get_attr("__module__", vm)
111+
}
112+
113+
#[pyproperty(magic)]
114+
fn qualname(&self, vm: &VirtualMachine) -> PyResult {
115+
self.callable.get_attr("__qualname__", vm)
116+
}
117+
118+
#[pyproperty(magic)]
119+
fn name(&self, vm: &VirtualMachine) -> PyResult {
120+
self.callable.get_attr("__name__", vm)
121+
}
122+
123+
#[pyproperty(magic)]
124+
fn annotations(&self, vm: &VirtualMachine) -> PyResult {
125+
self.callable.get_attr("__annotations__", vm)
126+
}
127+
128+
#[pyproperty(magic)]
129+
fn doc(&self, vm: &VirtualMachine) -> PyResult {
130+
self.callable.get_attr("__doc__", vm)
131+
}
132+
103133
#[pyproperty(magic)]
104134
fn isabstractmethod(&self, vm: &VirtualMachine) -> PyObjectRef {
105135
match vm.get_attribute_opt(self.callable.lock().clone(), "__isabstractmethod__") {

vm/src/builtins/staticmethod.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,36 @@ impl PyStaticMethod {
7373
self.callable.clone()
7474
}
7575

76+
#[pyproperty(magic)]
77+
fn wrapped(&self) -> PyObjectRef {
78+
self.callable.clone()
79+
}
80+
81+
#[pyproperty(magic)]
82+
fn module(&self, vm: &VirtualMachine) -> PyResult {
83+
self.callable.get_attr("__module__", vm)
84+
}
85+
86+
#[pyproperty(magic)]
87+
fn qualname(&self, vm: &VirtualMachine) -> PyResult {
88+
self.callable.get_attr("__qualname__", vm)
89+
}
90+
91+
#[pyproperty(magic)]
92+
fn name(&self, vm: &VirtualMachine) -> PyResult {
93+
self.callable.get_attr("__name__", vm)
94+
}
95+
96+
#[pyproperty(magic)]
97+
fn annotations(&self, vm: &VirtualMachine) -> PyResult {
98+
self.callable.get_attr("__annotations__", vm)
99+
}
100+
101+
#[pyproperty(magic)]
102+
fn doc(&self, vm: &VirtualMachine) -> PyResult {
103+
self.callable.get_attr("__doc__", vm)
104+
}
105+
76106
#[pyproperty(magic)]
77107
fn isabstractmethod(&self, vm: &VirtualMachine) -> PyObjectRef {
78108
match vm.get_attribute_opt(self.callable.clone(), "__isabstractmethod__") {

0 commit comments

Comments
 (0)