Skip to content

Commit 491fde8

Browse files
committed
Fix weakproxy getattr
1 parent 8ab4e77 commit 491fde8

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

vm/src/builtins/weakproxy.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::{PyStrRef, PyType, PyTypeRef, PyWeak};
22
use crate::{
33
class::PyClassImpl,
44
function::OptionalArg,
5-
types::{Constructor, SetAttr},
5+
types::{Constructor, GetAttr, SetAttr},
66
Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
77
};
88

@@ -57,14 +57,8 @@ crate::common::static_cell! {
5757
static WEAK_SUBCLASS: PyTypeRef;
5858
}
5959

60-
#[pyimpl(with(SetAttr, Constructor))]
60+
#[pyimpl(with(GetAttr, SetAttr, Constructor))]
6161
impl PyWeakProxy {
62-
// TODO: callbacks
63-
#[pymethod(magic)]
64-
fn getattr(&self, attr_name: PyStrRef, vm: &VirtualMachine) -> PyResult {
65-
let obj = self.weak.upgrade().ok_or_else(|| new_reference_error(vm))?;
66-
obj.get_attr(attr_name, vm)
67-
}
6862
#[pymethod(magic)]
6963
fn str(&self, vm: &VirtualMachine) -> PyResult<PyStrRef> {
7064
match self.weak.upgrade() {
@@ -81,6 +75,14 @@ fn new_reference_error(vm: &VirtualMachine) -> PyRef<super::PyBaseException> {
8175
)
8276
}
8377

78+
impl GetAttr for PyWeakProxy {
79+
// TODO: callbacks
80+
fn getattro(zelf: &Py<Self>, name: PyStrRef, vm: &VirtualMachine) -> PyResult {
81+
let obj = zelf.weak.upgrade().ok_or_else(|| new_reference_error(vm))?;
82+
obj.get_attr(name, vm)
83+
}
84+
}
85+
8486
impl SetAttr for PyWeakProxy {
8587
fn setattro(
8688
zelf: &crate::Py<Self>,

0 commit comments

Comments
 (0)