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

Method index

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

Source from the content-addressed store, hash-verified

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

Callers 1

try_index_optMethod · 0.45

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