MCPcopy Index your code
hub / github.com/RustPython/RustPython / __format__

Method __format__

crates/vm/src/builtins/complex.rs:357–373  ·  view source on GitHub ↗
(zelf: &Py<Self>, spec: PyUtf8StrRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

355
356 #[pymethod]
357 fn __format__(zelf: &Py<Self>, spec: PyUtf8StrRef, vm: &VirtualMachine) -> PyResult<Wtf8Buf> {
358 // Empty format spec: equivalent to str(self)
359 if spec.is_empty() {
360 return Ok(zelf.as_object().str(vm)?.as_wtf8().to_owned());
361 }
362 let format_spec =
363 FormatSpec::parse(spec.as_str()).map_err(|err| err.into_pyexception(vm))?;
364 let result = if format_spec.has_locale_format() {
365 let locale = crate::format::get_locale_info();
366 format_spec.format_complex_locale(&zelf.value, &locale)
367 } else {
368 format_spec.format_complex(&zelf.value)
369 };
370 result
371 .map(Wtf8Buf::from_string)
372 .map_err(|err| err.into_pyexception(vm))
373 }
374
375 #[pyclassmethod]
376 fn from_number(cls: PyTypeRef, number: PyObjectRef, vm: &VirtualMachine) -> PyResult {

Callers

nothing calls this directly

Calls 13

get_locale_infoFunction · 0.85
has_locale_formatMethod · 0.80
format_complex_localeMethod · 0.80
format_complexMethod · 0.80
parseFunction · 0.50
is_emptyMethod · 0.45
to_ownedMethod · 0.45
as_wtf8Method · 0.45
strMethod · 0.45
as_objectMethod · 0.45
as_strMethod · 0.45
into_pyexceptionMethod · 0.45

Tested by

no test coverage detected