Skip to content

Commit d4f33c4

Browse files
committed
extract empty_arguments_object helper
1 parent fb2c3ca commit d4f33c4

File tree

2 files changed

+17
-25
lines changed

2 files changed

+17
-25
lines changed

crates/vm/src/stdlib/ast.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,22 @@ fn node_add_location(
265265
.unwrap();
266266
}
267267

268+
/// Create an empty `arguments` AST node (no parameters).
269+
fn empty_arguments_object(vm: &VirtualMachine) -> PyObjectRef {
270+
let node = NodeAst
271+
.into_ref_with_type(vm, pyast::NodeArguments::static_type().to_owned())
272+
.unwrap();
273+
let dict = node.as_object().dict().unwrap();
274+
for list_field in ["posonlyargs", "args", "kwonlyargs", "kw_defaults", "defaults"] {
275+
dict.set_item(list_field, vm.ctx.new_list(vec![]).into(), vm)
276+
.unwrap();
277+
}
278+
for none_field in ["vararg", "kwarg"] {
279+
dict.set_item(none_field, vm.ctx.none(), vm).unwrap();
280+
}
281+
node.into()
282+
}
283+
268284
#[cfg(feature = "parser")]
269285
pub(crate) fn parse(
270286
vm: &VirtualMachine,

crates/vm/src/stdlib/ast/expression.rs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -330,31 +330,7 @@ impl Node for ast::ExprLambda {
330330
// Lambda with no parameters should have an empty arguments object, not None
331331
let args = match parameters {
332332
Some(params) => params.ast_to_object(vm, source_file),
333-
None => {
334-
// Create an empty arguments object
335-
let args_node = NodeAst
336-
.into_ref_with_type(vm, pyast::NodeArguments::static_type().to_owned())
337-
.unwrap();
338-
let args_dict = args_node.as_object().dict().unwrap();
339-
args_dict
340-
.set_item("posonlyargs", vm.ctx.new_list(vec![]).into(), vm)
341-
.unwrap();
342-
args_dict
343-
.set_item("args", vm.ctx.new_list(vec![]).into(), vm)
344-
.unwrap();
345-
args_dict.set_item("vararg", vm.ctx.none(), vm).unwrap();
346-
args_dict
347-
.set_item("kwonlyargs", vm.ctx.new_list(vec![]).into(), vm)
348-
.unwrap();
349-
args_dict
350-
.set_item("kw_defaults", vm.ctx.new_list(vec![]).into(), vm)
351-
.unwrap();
352-
args_dict.set_item("kwarg", vm.ctx.none(), vm).unwrap();
353-
args_dict
354-
.set_item("defaults", vm.ctx.new_list(vec![]).into(), vm)
355-
.unwrap();
356-
args_node.into()
357-
}
333+
None => empty_arguments_object(vm),
358334
};
359335
dict.set_item("args", args, vm).unwrap();
360336
dict.set_item("body", body.ast_to_object(vm, source_file), vm)

0 commit comments

Comments
 (0)