Skip to content

Commit b9b219d

Browse files
committed
Propagate method wrapper repr errors
Assisted-by: Codex:gpt-5.6-sol
1 parent 28454cc commit b9b219d

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

‎crates/vm/src/builtins/classmethod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl PyClassMethod {
195195
impl Representable for PyClassMethod {
196196
#[inline]
197197
fn repr_str(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<String> {
198-
let callable = zelf.callable.lock().repr(vm).unwrap();
198+
let callable = zelf.callable.lock().repr(vm)?;
199199
let class = Self::class(&vm.ctx);
200200

201201
let repr = match (

‎crates/vm/src/builtins/staticmethod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl Callable for PyStaticMethod {
179179

180180
impl Representable for PyStaticMethod {
181181
fn repr_str(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<String> {
182-
let callable = zelf.callable.lock().repr(vm).unwrap();
182+
let callable = zelf.callable.lock().repr(vm)?;
183183
let class = Self::class(&vm.ctx);
184184

185185
match (

‎extra_tests/snippets/syntax_class.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,29 @@ def t1(self):
163163
cm = classmethod(lambda cls: cls)
164164
assert cm.__func__(int) is int
165165

166+
167+
class Callback:
168+
def __init__(self, error):
169+
self.error = error
170+
171+
def __call__(self, *args, **kwargs):
172+
pass
173+
174+
def __repr__(self):
175+
raise self.error
176+
177+
178+
callback = Callback(RuntimeError("callback is unavailable"))
179+
180+
with assert_raises(RuntimeError) as caught:
181+
repr(staticmethod(callback))
182+
assert caught.exception is callback.error
183+
184+
with assert_raises(RuntimeError) as caught:
185+
repr(classmethod(callback))
186+
assert caught.exception is callback.error
187+
188+
166189
assert str(super(int, 5)) == "<super: <class 'int'>, <int object>>"
167190

168191
class T5(int):

0 commit comments

Comments
 (0)