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

Method float

crates/vm/src/protocol/number.rs:700–730  ·  view source on GitHub ↗
(self, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

698
699 #[inline]
700 pub fn float(self, vm: &VirtualMachine) -> Option<PyResult<PyRef<PyFloat>>> {
701 self.class().slots.as_number.float.load().map(|f| {
702 let ret = f(self, vm)?;
703
704 if let Some(ret) = ret.downcast_ref_if_exact::<PyFloat>(vm) {
705 return Ok(ret.to_owned());
706 }
707
708 let ret_class = ret.class().to_owned();
709 if let Some(ret) = ret.downcast_ref::<PyFloat>() {
710 _warnings::warn(
711 vm.ctx.exceptions.deprecation_warning,
712 format!(
713 "__float__ returned non-float (type {ret_class}). \
714 The ability to return an instance of a strict subclass of float \
715 is deprecated, and may be removed in a future version of Python."
716 ),
717 1,
718 vm,
719 )?;
720
721 Ok(ret.to_owned())
722 } else {
723 Err(vm.new_type_error(format!(
724 "{}.__float__ returned non-float(type {})",
725 self.class(),
726 ret_class
727 )))
728 }
729 })
730 }
731}
732
733pub fn handle_bytes_to_int_err(

Callers 1

try_float_optMethod · 0.80

Calls 7

fFunction · 0.50
warnFunction · 0.50
ErrClass · 0.50
mapMethod · 0.45
loadMethod · 0.45
classMethod · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected