From 92fe3fd668d848454330bd947f80dd48ff4aaf97 Mon Sep 17 00:00:00 2001 From: sijun-yang Date: Sun, 26 Jul 2026 13:49:19 +0900 Subject: [PATCH] Propagate method wrapper repr errors (#8371) Assisted-by: Codex:gpt-5.6-sol --- crates/vm/src/builtins/classmethod.rs | 2 +- crates/vm/src/builtins/staticmethod.rs | 2 +- extra_tests/snippets/syntax_class.py | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/crates/vm/src/builtins/classmethod.rs b/crates/vm/src/builtins/classmethod.rs index a6c69eb50..eb0e15ece 100644 --- a/crates/vm/src/builtins/classmethod.rs +++ b/crates/vm/src/builtins/classmethod.rs @@ -195,7 +195,7 @@ impl PyClassMethod { impl Representable for PyClassMethod { #[inline] fn repr_str(zelf: &Py, vm: &VirtualMachine) -> PyResult { - let callable = zelf.callable.lock().repr(vm).unwrap(); + let callable = zelf.callable.lock().repr(vm)?; let class = Self::class(&vm.ctx); let repr = match ( diff --git a/crates/vm/src/builtins/staticmethod.rs b/crates/vm/src/builtins/staticmethod.rs index 1ab697a0a..addfe8a4e 100644 --- a/crates/vm/src/builtins/staticmethod.rs +++ b/crates/vm/src/builtins/staticmethod.rs @@ -179,7 +179,7 @@ impl Callable for PyStaticMethod { impl Representable for PyStaticMethod { fn repr_str(zelf: &Py, vm: &VirtualMachine) -> PyResult { - let callable = zelf.callable.lock().repr(vm).unwrap(); + let callable = zelf.callable.lock().repr(vm)?; let class = Self::class(&vm.ctx); match ( diff --git a/extra_tests/snippets/syntax_class.py b/extra_tests/snippets/syntax_class.py index 4e80e7edf..4d1a99edf 100644 --- a/extra_tests/snippets/syntax_class.py +++ b/extra_tests/snippets/syntax_class.py @@ -163,6 +163,29 @@ assert T4.t1.__doc__ == "t1" cm = classmethod(lambda cls: cls) assert cm.__func__(int) is int + +class Callback: + def __init__(self, error): + self.error = error + + def __call__(self, *args, **kwargs): + pass + + def __repr__(self): + raise self.error + + +callback = Callback(RuntimeError("callback is unavailable")) + +with assert_raises(RuntimeError) as caught: + repr(staticmethod(callback)) +assert caught.exception is callback.error + +with assert_raises(RuntimeError) as caught: + repr(classmethod(callback)) +assert caught.exception is callback.error + + assert str(super(int, 5)) == ", >" class T5(int):