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

Method from_vectorcall

crates/vm/src/function/argument.rs:142–170  ·  view source on GitHub ↗

Create FuncArgs from a vectorcall-style argument slice (PEP 590). `args[..nargs]` are positional, and if `kwnames` is provided, the last `kwnames.len()` entries in `args[nargs..]` are keyword values. Convert borrowed vectorcall args to FuncArgs (clones all values).

(
        args: &[PyObjectRef],
        nargs: usize,
        kwnames: Option<&[PyObjectRef]>,
    )

Source from the content-addressed store, hash-verified

140 /// the last `kwnames.len()` entries in `args[nargs..]` are keyword values.
141 /// Convert borrowed vectorcall args to FuncArgs (clones all values).
142 pub fn from_vectorcall(
143 args: &[PyObjectRef],
144 nargs: usize,
145 kwnames: Option<&[PyObjectRef]>,
146 ) -> Self {
147 debug_assert!(nargs <= args.len());
148 debug_assert!(kwnames.is_none_or(|kw| nargs + kw.len() <= args.len()));
149 let pos_args = args[..nargs].to_vec();
150 let kwargs = if let Some(names) = kwnames {
151 names
152 .iter()
153 .zip(&args[nargs..nargs + names.len()])
154 .map(|(name, val)| {
155 let key = name
156 .downcast_ref::<crate::builtins::PyUtf8Str>()
157 .expect("kwnames must be strings")
158 .as_str()
159 .to_owned();
160 (key, val.clone())
161 })
162 .collect()
163 } else {
164 IndexMap::new()
165 };
166 Self {
167 args: pos_args,
168 kwargs,
169 }
170 }
171
172 /// Convert owned vectorcall args to FuncArgs (moves values, no clone).
173 pub fn from_vectorcall_owned(

Callers

nothing calls this directly

Calls 9

newFunction · 0.85
to_vecMethod · 0.80
collectMethod · 0.80
mapMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45
to_ownedMethod · 0.45
as_strMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected