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

Method int

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

Source from the content-addressed store, hash-verified

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>> {

Callers 1

try_intMethod · 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