Skip to content

Commit 11a59bb

Browse files
authored
Merge pull request #6835 from youknowone/updatelib-ci
CI runs update_lib
2 parents 8cbaf3c + 43bd494 commit 11a59bb

3 files changed

Lines changed: 56 additions & 6 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,11 @@ jobs:
463463

464464
- run: ruff format --check
465465

466+
- name: run update_lib tests
467+
run: cargo run -- -m unittest discover -s scripts/update_lib/tests -v
468+
env:
469+
PYTHONPATH: scripts
470+
466471
- name: install prettier
467472
run: yarn global add prettier && echo "$(yarn global bin)" >>$GITHUB_PATH
468473

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

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
use super::*;
44
use crate::common::ascii;
5+
use crate::function::FuncArgs;
6+
use crate::types::Initializer;
57

68
macro_rules! impl_node {
79
(
@@ -462,12 +464,54 @@ impl_node!(
462464
attributes: ["lineno", "col_offset", "end_lineno", "end_col_offset"],
463465
);
464466

465-
impl_node!(
466-
#[pyclass(module = "_ast", name = "Constant", base = NodeExpr)]
467-
pub(crate) struct NodeExprConstant,
468-
fields: ["value", "kind"],
469-
attributes: ["lineno", "col_offset", "end_lineno", "end_col_offset"],
470-
);
467+
// NodeExprConstant needs custom Initializer to default kind to None
468+
#[pyclass(module = "_ast", name = "Constant", base = NodeExpr)]
469+
#[repr(transparent)]
470+
pub(crate) struct NodeExprConstant(NodeExpr);
471+
472+
#[pyclass(flags(HAS_DICT, BASETYPE), with(Initializer))]
473+
impl NodeExprConstant {
474+
#[extend_class]
475+
fn extend_class_with_fields(ctx: &Context, class: &'static Py<PyType>) {
476+
class.set_attr(
477+
identifier!(ctx, _fields),
478+
ctx.new_tuple(vec![
479+
ctx.new_str(ascii!("value")).into(),
480+
ctx.new_str(ascii!("kind")).into(),
481+
])
482+
.into(),
483+
);
484+
485+
class.set_attr(
486+
identifier!(ctx, _attributes),
487+
ctx.new_list(vec![
488+
ctx.new_str(ascii!("lineno")).into(),
489+
ctx.new_str(ascii!("col_offset")).into(),
490+
ctx.new_str(ascii!("end_lineno")).into(),
491+
ctx.new_str(ascii!("end_col_offset")).into(),
492+
])
493+
.into(),
494+
);
495+
}
496+
}
497+
498+
impl Initializer for NodeExprConstant {
499+
type Args = FuncArgs;
500+
501+
fn slot_init(zelf: PyObjectRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult<()> {
502+
<NodeAst as Initializer>::slot_init(zelf.clone(), args, vm)?;
503+
// kind defaults to None if not provided
504+
let dict = zelf.as_object().dict().unwrap();
505+
if !dict.contains_key("kind", vm) {
506+
dict.set_item("kind", vm.ctx.none(), vm)?;
507+
}
508+
Ok(())
509+
}
510+
511+
fn init(_zelf: PyRef<Self>, _args: Self::Args, _vm: &VirtualMachine) -> PyResult<()> {
512+
unreachable!("slot_init is defined")
513+
}
514+
}
471515

472516
impl_node!(
473517
#[pyclass(module = "_ast", name = "Attribute", base = NodeExpr)]

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub(crate) mod _ast {
8080
}
8181
zelf.set_attr(vm.ctx.intern_str(key), value, vm)?;
8282
}
83+
8384
Ok(())
8485
}
8586

0 commit comments

Comments
 (0)