| 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 | |
| 733 | pub fn handle_bytes_to_int_err( |