Allow None as with_tracebak arg

This commit is contained in:
Aviv Palivoda
2019-11-02 12:23:57 +02:00
parent 1fb868a08a
commit 74b6d7c0f5
2 changed files with 16 additions and 2 deletions

View File

@@ -15,3 +15,13 @@ try:
except KeyError as ex2:
tb = traceback.extract_tb(ex2.__traceback__)
assert tb[1].line == "1/0"
try:
try:
1/0
except ZeroDivisionError as ex:
raise ex.with_traceback(None)
except ZeroDivisionError as ex2:
tb = traceback.extract_tb(ex2.__traceback__)
assert len(tb) == 1

View File

@@ -210,10 +210,14 @@ fn exception_repr(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
fn exception_with_traceback(
zelf: PyObjectRef,
tb: PyTracebackRef,
tb: Option<PyTracebackRef>,
vm: &VirtualMachine,
) -> PyResult {
vm.set_attr(&zelf, "__traceback__", tb)?;
vm.set_attr(
&zelf,
"__traceback__",
tb.map_or(vm.get_none(), |tb| tb.into_object()),
)?;
Ok(zelf)
}