ast: Populate _field_types with real type objects - #6981
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