| 665 | |
| 666 | #[inline] |
| 667 | pub fn index(self, vm: &VirtualMachine) -> Option<PyResult<PyIntRef>> { |
| 668 | self.class().slots.as_number.index.load().map(|f| { |
| 669 | let ret = f(self, vm)?; |
| 670 | |
| 671 | if let Some(ret) = ret.downcast_ref_if_exact::<PyInt>(vm) { |
| 672 | return Ok(ret.to_owned()); |
| 673 | } |
| 674 | |
| 675 | let ret_class = ret.class().to_owned(); |
| 676 | if let Some(ret) = ret.downcast_ref::<PyInt>() { |
| 677 | _warnings::warn( |
| 678 | vm.ctx.exceptions.deprecation_warning, |
| 679 | format!( |
| 680 | "__index__ returned non-int (type {ret_class}). \ |
| 681 | The ability to return an instance of a strict subclass of int \ |
| 682 | is deprecated, and may be removed in a future version of Python." |
| 683 | ), |
| 684 | 1, |
| 685 | vm, |
| 686 | )?; |
| 687 | |
| 688 | Ok(ret.to_owned()) |
| 689 | } else { |
| 690 | Err(vm.new_type_error(format!( |
| 691 | "{}.__index__ returned non-int(type {})", |
| 692 | self.class(), |
| 693 | ret_class |
| 694 | ))) |
| 695 | } |
| 696 | }) |
| 697 | } |
| 698 | |
| 699 | #[inline] |
| 700 | pub fn float(self, vm: &VirtualMachine) -> Option<PyResult<PyRef<PyFloat>>> { |