stop panic on to_string, report using write_unraisable instead
This commit is contained in:
parent
c27a6333d6
commit
5aff2ccc9e
|
@ -0,0 +1 @@
|
||||||
|
Stop panic on `fmt::Display`, instead return `"<unprintable object>"` string and report error via `sys.unraisablehook()`
|
|
@ -99,8 +99,15 @@ macro_rules! pyobject_native_type_base(
|
||||||
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>)
|
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>)
|
||||||
-> ::std::result::Result<(), ::std::fmt::Error>
|
-> ::std::result::Result<(), ::std::fmt::Error>
|
||||||
{
|
{
|
||||||
let s = self.str().or(::std::result::Result::Err(::std::fmt::Error))?;
|
match self.str() {
|
||||||
f.write_str(&s.to_string_lossy())
|
::std::result::Result::Ok(s) => return f.write_str(&s.to_string_lossy()),
|
||||||
|
::std::result::Result::Err(err) => err.write_unraisable(self.py(), ::std::option::Option::Some(self)),
|
||||||
|
}
|
||||||
|
|
||||||
|
match self.get_type().name() {
|
||||||
|
::std::result::Result::Ok(name) => ::std::write!(f, "<unprintable {} object>", name),
|
||||||
|
::std::result::Result::Err(_err) => f.write_str("<unprintable object>"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue