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

Method __format__

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

Source from the content-addressed store, hash-verified

255impl PyFloat {
256 #[pymethod]
257 fn __format__(zelf: &Py<Self>, spec: PyUtf8StrRef, vm: &VirtualMachine) -> PyResult<Wtf8Buf> {
258 // Empty format spec: equivalent to str(self)
259 if spec.is_empty() {
260 return Ok(zelf.as_object().str(vm)?.as_wtf8().to_owned());
261 }
262 let format_spec =
263 FormatSpec::parse(spec.as_str()).map_err(|err| err.into_pyexception(vm))?;
264 let result = if format_spec.has_locale_format() {
265 let locale = crate::format::get_locale_info();
266 format_spec.format_float_locale(zelf.value, &locale)
267 } else {
268 format_spec.format_float(zelf.value)
269 };
270 result
271 .map(Wtf8Buf::from_string)
272 .map_err(|err| err.into_pyexception(vm))
273 }
274
275 #[pystaticmethod]
276 fn __getformat__(spec: PyUtf8StrRef, vm: &VirtualMachine) -> PyResult<String> {

Callers

nothing calls this directly

Calls 13

get_locale_infoFunction · 0.85
has_locale_formatMethod · 0.80
format_float_localeMethod · 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
format_floatMethod · 0.45

Tested by

no test coverage detected