handle panic if str is not defined in unraisablehook (#4864)

This commit is contained in:
Ankit Kumar Pandey authored and GitHub committed 2023-04-15 23:47:19 +09:00
1 parent c9546c2419
commit cb6cf107ba
2 files changed
+18 -1

No files matched your search

+10
View File
@@ -19,3 +19,13 @@ assert_raises(NameError, lambda: y) # noqa: F821
with assert_raises(NameError):
del y # noqa: F821
# see https://github.com/RustPython/RustPython/issues/4863
class MyTest:
def __del__(self):
type(self)()
def test_del_panic():
mytest = MyTest()
del mytest
+8 -1
View File
@@ -590,7 +590,14 @@ mod sys {
fn unraisablehook(unraisable: UnraisableHookArgs, vm: &VirtualMachine) {
if let Err(e) = _unraisablehook(unraisable, vm) {
let stderr = super::PyStderr(vm);
writeln!(stderr, "{}", e.as_object().repr(vm).unwrap().as_str());
writeln!(
stderr,
"{}",
e.as_object()
.repr(vm)
.unwrap_or_else(|_| vm.ctx.empty_str.to_owned())
.as_str()
);
}
}