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

Function get_future_repr_info

crates/stdlib/src/_asyncio.rs:851–895  ·  view source on GitHub ↗
(future: &PyObject, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

849 }
850
851 fn get_future_repr_info(future: &PyObject, vm: &VirtualMachine) -> PyResult<Wtf8Buf> {
852 // Try to use asyncio.base_futures._future_repr_info
853 // Import from sys.modules if available, otherwise try regular import
854 let sys_modules = vm.sys_module.get_attr("modules", vm)?;
855 let module =
856 if let Ok(m) = sys_modules.get_item(&*vm.ctx.new_str("asyncio.base_futures"), vm) {
857 m
858 } else {
859 // vm.import returns the top-level module, get base_futures submodule
860 match vm
861 .import("asyncio.base_futures", 0)
862 .and_then(|asyncio| asyncio.get_attr(vm.ctx.intern_str("base_futures"), vm))
863 {
864 Ok(m) => m,
865 Err(_) => return get_future_repr_info_fallback(future, vm),
866 }
867 };
868
869 let func = match vm.get_attribute_opt(module, vm.ctx.intern_str("_future_repr_info")) {
870 Ok(Some(f)) => f,
871 _ => return get_future_repr_info_fallback(future, vm),
872 };
873
874 let info = match func.call((future.to_owned(),), vm) {
875 Ok(i) => i,
876 Err(_) => return get_future_repr_info_fallback(future, vm),
877 };
878
879 let list: PyListRef = match info.downcast() {
880 Ok(l) => l,
881 Err(_) => return get_future_repr_info_fallback(future, vm),
882 };
883
884 let mut result = Wtf8Buf::new();
885 let parts = list.borrow_vec();
886 for (i, x) in parts.iter().enumerate() {
887 if i > 0 {
888 result.push_str(" ");
889 }
890 if let Ok(s) = x.str(vm) {
891 result.push_wtf8(s.as_wtf8());
892 }
893 }
894 Ok(result)
895 }
896
897 fn get_future_repr_info_fallback(future: &PyObject, vm: &VirtualMachine) -> PyResult<Wtf8Buf> {
898 // Fallback: build repr from properties directly

Callers 2

repr_strMethod · 0.85
get_task_repr_infoFunction · 0.85

Calls 15

newFunction · 0.85
intern_strMethod · 0.80
get_attribute_optMethod · 0.80
downcastMethod · 0.80
borrow_vecMethod · 0.80
push_wtf8Method · 0.80
get_attrMethod · 0.45
get_itemMethod · 0.45
new_strMethod · 0.45
importMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected