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
11 changes: 9 additions & 2 deletions py/exception.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,16 @@ func (e *Exception) M__str__() (Object, error) {
}

func (e *Exception) M__repr__() (Object, error) {
msg := e.Args.(Tuple)[0].(String)
typ := e.Base.Name
return String(fmt.Sprintf("%s(%q)", typ, string(msg))), nil
args := e.Args.(Tuple)
if len(args) == 0 {
return String(fmt.Sprintf("%s()", typ)), nil
}
msg, err := args.M__repr__()
if err != nil {
return nil, err
}
return String(fmt.Sprintf("%s%s", typ, string(msg.(String)))), nil
}

// Check Interfaces
Expand Down
6 changes: 6 additions & 0 deletions vm/tests/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,10 @@
ok = True
assert ok, "ValueError not raised"

doc = "exception repr"
repr(ValueError()) == "ValueError()"
repr(ValueError(1)) == "ValueError(1)"
repr(ValueError(1, 2, 3)) == "ValueError(1, 2, 3)"
repr(ValueError("failed")) == 'ValueError("failed")'

doc = "finished"
Loading