Skip to content
This repository was archived by the owner on May 11, 2023. It is now read-only.

Commit cb6cf10

Browse files
authored
handle panic if str is not defined in unraisablehook (RustPython#4864)
1 parent c9546c2 commit cb6cf10

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

extra_tests/snippets/syntax_del.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,13 @@ class MyObject: pass
1919

2020
with assert_raises(NameError):
2121
del y # noqa: F821
22+
23+
# see https://github.com/RustPython/RustPython/issues/4863
24+
25+
class MyTest:
26+
def __del__(self):
27+
type(self)()
28+
29+
def test_del_panic():
30+
mytest = MyTest()
31+
del mytest

vm/src/stdlib/sys.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,14 @@ mod sys {
590590
fn unraisablehook(unraisable: UnraisableHookArgs, vm: &VirtualMachine) {
591591
if let Err(e) = _unraisablehook(unraisable, vm) {
592592
let stderr = super::PyStderr(vm);
593-
writeln!(stderr, "{}", e.as_object().repr(vm).unwrap().as_str());
593+
writeln!(
594+
stderr,
595+
"{}",
596+
e.as_object()
597+
.repr(vm)
598+
.unwrap_or_else(|_| vm.ctx.empty_str.to_owned())
599+
.as_str()
600+
);
594601
}
595602
}
596603

0 commit comments

Comments
 (0)