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

Method __format__

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

Source from the content-addressed store, hash-verified

494
495 #[pymethod]
496 fn __format__(zelf: &Py<Self>, spec: PyUtf8StrRef, vm: &VirtualMachine) -> PyResult<Wtf8Buf> {
497 // Empty format spec on a subclass: equivalent to str(self)
498 if spec.is_empty() && !zelf.class().is(vm.ctx.types.int_type) {
499 return Ok(zelf.as_object().str(vm)?.as_wtf8().to_owned());
500 }
501 let format_spec =
502 FormatSpec::parse(spec.as_str()).map_err(|err| err.into_pyexception(vm))?;
503 let result = if format_spec.has_locale_format() {
504 let locale = crate::format::get_locale_info();
505 format_spec.format_int_locale(&zelf.value, &locale)
506 } else {
507 format_spec.format_int(&zelf.value)
508 };
509 result
510 .map(Wtf8Buf::from_string)
511 .map_err(|err| err.into_pyexception(vm))
512 }
513
514 #[pymethod]
515 fn __sizeof__(&self) -> usize {

Callers

nothing calls this directly

Calls 15

get_locale_infoFunction · 0.85
isMethod · 0.80
has_locale_formatMethod · 0.80
format_int_localeMethod · 0.80
format_intMethod · 0.80
parseFunction · 0.50
is_emptyMethod · 0.45
classMethod · 0.45
to_ownedMethod · 0.45
as_wtf8Method · 0.45
strMethod · 0.45
as_objectMethod · 0.45

Tested by

no test coverage detected