From 0ba57b0632419a9fbc12a09a8009f5d40e46cad8 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Thu, 22 Jan 2026 20:45:50 +0900 Subject: [PATCH 1/2] Fix ast.Constant.__init__ --- crates/vm/src/stdlib/ast/pyast.rs | 56 ++++++++++++++++++++++++++---- crates/vm/src/stdlib/ast/python.rs | 1 + 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/crates/vm/src/stdlib/ast/pyast.rs b/crates/vm/src/stdlib/ast/pyast.rs index f5e9d9f6d93..2131df29b96 100644 --- a/crates/vm/src/stdlib/ast/pyast.rs +++ b/crates/vm/src/stdlib/ast/pyast.rs @@ -2,6 +2,8 @@ use super::*; use crate::common::ascii; +use crate::function::FuncArgs; +use crate::types::Initializer; macro_rules! impl_node { ( @@ -462,12 +464,54 @@ impl_node!( attributes: ["lineno", "col_offset", "end_lineno", "end_col_offset"], ); -impl_node!( - #[pyclass(module = "_ast", name = "Constant", base = NodeExpr)] - pub(crate) struct NodeExprConstant, - fields: ["value", "kind"], - attributes: ["lineno", "col_offset", "end_lineno", "end_col_offset"], -); +// NodeExprConstant needs custom Initializer to default kind to None +#[pyclass(module = "_ast", name = "Constant", base = NodeExpr)] +#[repr(transparent)] +pub(crate) struct NodeExprConstant(NodeExpr); + +#[pyclass(flags(HAS_DICT, BASETYPE), with(Initializer))] +impl NodeExprConstant { + #[extend_class] + fn extend_class_with_fields(ctx: &Context, class: &'static Py) { + class.set_attr( + identifier!(ctx, _fields), + ctx.new_tuple(vec![ + ctx.new_str(ascii!("value")).into(), + ctx.new_str(ascii!("kind")).into(), + ]) + .into(), + ); + + class.set_attr( + identifier!(ctx, _attributes), + ctx.new_list(vec![ + ctx.new_str(ascii!("lineno")).into(), + ctx.new_str(ascii!("col_offset")).into(), + ctx.new_str(ascii!("end_lineno")).into(), + ctx.new_str(ascii!("end_col_offset")).into(), + ]) + .into(), + ); + } +} + +impl Initializer for NodeExprConstant { + type Args = FuncArgs; + + fn slot_init(zelf: PyObjectRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult<()> { + ::slot_init(zelf.clone(), args, vm)?; + // kind defaults to None if not provided + let dict = zelf.as_object().dict().unwrap(); + if !dict.contains_key("kind", vm) { + dict.set_item("kind", vm.ctx.none(), vm)?; + } + Ok(()) + } + + fn init(_zelf: PyRef, _args: Self::Args, _vm: &VirtualMachine) -> PyResult<()> { + unreachable!("slot_init is defined") + } +} impl_node!( #[pyclass(module = "_ast", name = "Attribute", base = NodeExpr)] diff --git a/crates/vm/src/stdlib/ast/python.rs b/crates/vm/src/stdlib/ast/python.rs index 2ae07c34d07..6c38b00f9ad 100644 --- a/crates/vm/src/stdlib/ast/python.rs +++ b/crates/vm/src/stdlib/ast/python.rs @@ -80,6 +80,7 @@ pub(crate) mod _ast { } zelf.set_attr(vm.ctx.intern_str(key), value, vm)?; } + Ok(()) } From 43bd4940ea5c7d31d872d6180e479a06e058297c Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Wed, 21 Jan 2026 06:14:11 +0900 Subject: [PATCH 2/2] CI tests update_lib --- .github/workflows/ci.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 79c780c4f85..720cd53d3bc 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -463,6 +463,11 @@ jobs: - run: ruff format --check + - name: run update_lib tests + run: cargo run -- -m unittest discover -s scripts/update_lib/tests -v + env: + PYTHONPATH: scripts + - name: install prettier run: yarn global add prettier && echo "$(yarn global bin)" >>$GITHUB_PATH