| 632 | |
| 633 | #[inline] |
| 634 | pub fn int(self, vm: &VirtualMachine) -> Option<PyResult<PyIntRef>> { |
| 635 | self.class().slots.as_number.int.load().map(|f| { |
| 636 | let ret = f(self, vm)?; |
| 637 | |
| 638 | if let Some(ret) = ret.downcast_ref_if_exact::<PyInt>(vm) { |
| 639 | return Ok(ret.to_owned()); |
| 640 | } |
| 641 | |
| 642 | let ret_class = ret.class().to_owned(); |
| 643 | if let Some(ret) = ret.downcast_ref::<PyInt>() { |
| 644 | _warnings::warn( |
| 645 | vm.ctx.exceptions.deprecation_warning, |
| 646 | format!( |
| 647 | "__int__ returned non-int (type {ret_class}). \ |
| 648 | The ability to return an instance of a strict subclass of int \ |
| 649 | is deprecated, and may be removed in a future version of Python." |
| 650 | ), |
| 651 | 1, |
| 652 | vm, |
| 653 | )?; |
| 654 | |
| 655 | Ok(ret.to_owned()) |
| 656 | } else { |
| 657 | Err(vm.new_type_error(format!( |
| 658 | "{}.__int__ returned non-int(type {})", |
| 659 | self.class(), |
| 660 | ret_class |
| 661 | ))) |
| 662 | } |
| 663 | }) |
| 664 | } |
| 665 | |
| 666 | #[inline] |
| 667 | pub fn index(self, vm: &VirtualMachine) -> Option<PyResult<PyIntRef>> { |