MCPcopy Create free account
hub / github.com/PyO3/pyo3 / python_format

Function python_format

src/instance.rs:776–790  ·  view source on GitHub ↗
(
    any: &Bound<'_, PyAny>,
    format_result: PyResult<Bound<'_, PyString>>,
    f: &mut core::fmt::Formatter<'_>,
)

Source from the content-addressed store, hash-verified

774}
775
776fn python_format(
777 any: &Bound<'_, PyAny>,
778 format_result: PyResult<Bound<'_, PyString>>,
779 f: &mut core::fmt::Formatter<'_>,
780) -> Result<(), core::fmt::Error> {
781 match format_result {
782 Result::Ok(s) => return f.write_str(&s.to_string_lossy()),
783 Result::Err(err) => err.write_unraisable(any.py(), Some(any)),
784 }
785
786 match any.get_type().name() {
787 Result::Ok(name) => core::write!(f, "<unprintable {name} object>"),
788 Result::Err(_err) => f.write_str("<unprintable object>"),
789 }
790}
791
792// The trait bound is needed to avoid running into the auto-deref recursion
793// limit (error[E0055]), because `Bound<PyAny>` would deref into itself. See:

Callers 1

fmtMethod · 0.85

Calls 6

write_strMethod · 0.80
to_string_lossyMethod · 0.80
write_unraisableMethod · 0.80
pyMethod · 0.45
nameMethod · 0.45
get_typeMethod · 0.45

Tested by

no test coverage detected