mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Propagate method wrapper repr errors (#8371)
Assisted-by: Codex:gpt-5.6-sol
This commit is contained in:
1 parent
44e5d84659
commit
92fe3fd668
3 files changed
+25
-2
No files matched your search
@@ -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 (
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in new issue
Block a user