Convert owned vectorcall args to FuncArgs (moves values, no clone).
(
mut args: Vec<PyObjectRef>,
nargs: usize,
kwnames: Option<&[PyObjectRef]>,
)
| 171 | |
| 172 | /// Convert owned vectorcall args to FuncArgs (moves values, no clone). |
| 173 | pub fn from_vectorcall_owned( |
| 174 | mut args: Vec<PyObjectRef>, |
| 175 | nargs: usize, |
| 176 | kwnames: Option<&[PyObjectRef]>, |
| 177 | ) -> Self { |
| 178 | debug_assert!(nargs <= args.len()); |
| 179 | debug_assert!(kwnames.is_none_or(|kw| nargs + kw.len() <= args.len())); |
| 180 | let kwargs = if let Some(names) = kwnames { |
| 181 | let kw_count = names.len(); |
| 182 | names |
| 183 | .iter() |
| 184 | .zip(args.drain(nargs..nargs + kw_count)) |
| 185 | .map(|(name, val)| { |
| 186 | let key = name |
| 187 | .downcast_ref::<crate::builtins::PyUtf8Str>() |
| 188 | .expect("kwnames must be strings") |
| 189 | .as_str() |
| 190 | .to_owned(); |
| 191 | (key, val) |
| 192 | }) |
| 193 | .collect() |
| 194 | } else { |
| 195 | IndexMap::new() |
| 196 | }; |
| 197 | args.truncate(nargs); |
| 198 | Self { args, kwargs } |
| 199 | } |
| 200 | |
| 201 | pub fn is_empty(&self) -> bool { |
| 202 | self.args.is_empty() && self.kwargs.is_empty() |