(future: &PyObject, vm: &VirtualMachine)
| 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 |
no test coverage detected