Propagate method wrapper repr errors (#8371)

Assisted-by: Codex:gpt-5.6-sol
This commit is contained in:
sijun-yang authored and GitHub committed 2026-07-26 13:49:19 +09:00
1 parent 44e5d84659
commit 92fe3fd668
3 files changed
+25 -2

No files matched your search

+1 -1
View File
@@ -195,7 +195,7 @@ impl PyClassMethod {
impl Representable for PyClassMethod {
#[inline]
fn repr_str(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<String> {
let callable = zelf.callable.lock().repr(vm).unwrap();
let callable = zelf.callable.lock().repr(vm)?;
let class = Self::class(&vm.ctx);
let repr = match (
+1 -1
View File
@@ -179,7 +179,7 @@ impl Callable for PyStaticMethod {
impl Representable for PyStaticMethod {
fn repr_str(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<String> {
let callable = zelf.callable.lock().repr(vm).unwrap();
let callable = zelf.callable.lock().repr(vm)?;
let class = Self::class(&vm.ctx);
match (
+23
View File
@@ -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)) == "<super: <class 'int'>, <int object>>"
class T5(int):