Skip to content

Commit 8852abc

Browse files
committed
make exception __repr__ compatible with python3.6
1 parent 1e53e6c commit 8852abc

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

tests/snippets/exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
exc = KeyError('message')
88
assert str(exc) == "'message'"
9-
assert repr(exc) == "KeyError('message')"
9+
assert repr(exc) == "KeyError('message',)"
1010

1111
exc = KeyError('message', 'another message')
1212
assert str(exc) == "('message', 'another message')"
@@ -22,4 +22,4 @@ def __str__(self):
2222

2323
exc = KeyError(A())
2424
assert str(exc) == 'repr'
25-
assert repr(exc) == 'KeyError(repr)'
25+
assert repr(exc) == 'KeyError(repr,)'

vm/src/exceptions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ fn exception_repr(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
185185
let exc_name = exc.class().name.clone();
186186
let joined_str = match args_repr.len() {
187187
0 => format!("{}()", exc_name),
188+
1 => format!("{}({},)", exc_name, args_repr[0]),
188189
_ => format!("{}({})", exc_name, args_repr.join(", ")),
189190
};
190191
Ok(vm.new_str(joined_str))

0 commit comments

Comments
 (0)