Skip to content

Commit 4c97056

Browse files
committed
Fix __doc__ attribute
1 parent c3d1417 commit 4c97056

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

vm/src/builtins/classmethod.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,21 @@ impl Constructor for PyClassMethod {
6464
type Args = PyObjectRef;
6565

6666
fn py_new(cls: PyTypeRef, callable: Self::Args, vm: &VirtualMachine) -> PyResult {
67-
PyClassMethod {
67+
let _callable = callable.clone();
68+
let result: PyResult<PyObjectRef> = PyClassMethod {
6869
callable: PyMutex::new(callable),
6970
}
7071
.into_ref_with_type(vm, cls)
71-
.map(Into::into)
72+
.map(Into::into);
73+
74+
let doc: PyResult<PyObjectRef> = _callable.get_attr("__doc__", vm);
75+
let doc = vm.unwrap_pyresult(doc);
76+
let obj = vm.unwrap_pyresult(result.clone());
77+
78+
match obj.set_attr("__doc__", doc, vm) {
79+
Err(e) => Err(e),
80+
Ok(_) => result,
81+
}
7282
}
7383
}
7484

@@ -102,32 +112,27 @@ impl PyClassMethod {
102112

103113
#[pyproperty(magic)]
104114
fn wrapped(&self) -> PyObjectRef {
105-
self.callable.clone()
115+
self.callable.lock().clone()
106116
}
107117

108118
#[pyproperty(magic)]
109119
fn module(&self, vm: &VirtualMachine) -> PyResult {
110-
self.callable.get_attr("__module__", vm)
120+
self.callable.lock().get_attr("__module__", vm)
111121
}
112122

113123
#[pyproperty(magic)]
114124
fn qualname(&self, vm: &VirtualMachine) -> PyResult {
115-
self.callable.get_attr("__qualname__", vm)
125+
self.callable.lock().get_attr("__qualname__", vm)
116126
}
117127

118128
#[pyproperty(magic)]
119129
fn name(&self, vm: &VirtualMachine) -> PyResult {
120-
self.callable.get_attr("__name__", vm)
130+
self.callable.lock().get_attr("__name__", vm)
121131
}
122132

123133
#[pyproperty(magic)]
124134
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)
135+
self.callable.lock().get_attr("__annotations__", vm)
131136
}
132137

133138
#[pyproperty(magic)]

vm/src/builtins/staticmethod.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,19 @@ impl Constructor for PyStaticMethod {
4141
type Args = PyObjectRef;
4242

4343
fn py_new(cls: PyTypeRef, callable: Self::Args, vm: &VirtualMachine) -> PyResult {
44-
PyStaticMethod { callable }
44+
let _callable = callable.clone();
45+
let result: PyResult<PyObjectRef> = PyStaticMethod { callable }
4546
.into_ref_with_type(vm, cls)
46-
.map(Into::into)
47+
.map(Into::into);
48+
49+
let doc: PyResult<PyObjectRef> = _callable.get_attr("__doc__", vm);
50+
let doc = vm.unwrap_pyresult(doc);
51+
let obj = vm.unwrap_pyresult(result.clone());
52+
53+
match obj.set_attr("__doc__", doc, vm) {
54+
Err(e) => Err(e),
55+
Ok(_) => result,
56+
}
4757
}
4858
}
4959

@@ -98,11 +108,6 @@ impl PyStaticMethod {
98108
self.callable.get_attr("__annotations__", vm)
99109
}
100110

101-
#[pyproperty(magic)]
102-
fn doc(&self, vm: &VirtualMachine) -> PyResult {
103-
self.callable.get_attr("__doc__", vm)
104-
}
105-
106111
#[pyproperty(magic)]
107112
fn isabstractmethod(&self, vm: &VirtualMachine) -> PyObjectRef {
108113
match vm.get_attribute_opt(self.callable.clone(), "__isabstractmethod__") {

0 commit comments

Comments
 (0)