ast: Populate _field_types with real type objects#6981
ast: Populate _field_types with real type objects#6981youknowone merged 2 commits intoRustPython:mainfrom
Conversation
- Add FieldType enum and FIELD_TYPES static table mapping all AST node classes to their ASDL field types - Resolve markers to real Python type objects (GenericAlias, Union, plain types) at module init in populate_field_types() - Set class-level None defaults for optional fields - Replace hardcoded LIST_FIELDS and class-name checks in slot_init with _field_types-based lookup - Add expr_context default to Load(), fix ImportFrom.level default (now None instead of 0) - Fix __class_getitem__ None check, compile() formatting - Remove 14 @expectedfailure decorators from test_ast
📝 WalkthroughWalkthroughThis PR refactors the AST field initialization system by introducing a type-driven approach. It adds a FieldType enum, a FIELD_TYPES constant enumerating AST class fields, and a populate_field_types function to dynamically resolve and populate _field_types attributes on AST classes at module initialization, replacing prior hard-coded defaulting logic. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] lib: cpython/Lib/ast.py dependencies:
dependent tests: (48 tests)
Legend:
|
Summary by CodeRabbit