Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/vm/src/builtins/classmethod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/builtins/staticmethod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
23 changes: 23 additions & 0 deletions extra_tests/snippets/syntax_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,29 @@ def t1(self):
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):
Expand Down
Loading