Repository navigation
gh-135797: Add _field_types to abstract AST classes - #159567
Open
Wojusensei wants to merge 1 commit into
Open
Wojusensei wants to merge 1 commit into
Wojusensei wants to merge 1 commit into
Conversation
Wojusensei
requested review from
Eclips4,
lysnikolaou,
pablogsal and
tomasr8
as code owners
October 16, 2026 19:18
Documentation build overview
4 files changed± library/ast.html± library/calendar.html± library/test.html± whatsnew/changelog.html |
Classes without fields never got a _field_types dictionary, so the attribute was missing on ast.AST and on the abstract classes such as ast.mod, while typeshed declares it on ast.AST. make_type() now sets an empty dictionary on every class it creates, and ast.AST gets one too; add_ast_annotations() keeps filling in the concrete classes. The constructor relied on the missing attribute to detect user subclasses that declare _fields but no _field_types, and those must keep working as before 3.13. An empty dictionary is treated the same way now, otherwise they would start failing with a missing-field TypeError.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Classes without fields have always had an empty
_fieldstuple, but they never got a_field_typesdictionary, so the attribute was missing onast.ASTand on the abstract classes such asast.mod, while typeshed declares it onast.AST.make_type()now sets an empty dictionary on every class it creates, andast.ASTgets one toothe constructor used the missing attribute to tell user subclasses that declare
_fieldsbut no_field_typesapart from the built-in nodes. an empty dictionary is handled the same way now, so those subclasses keep the behavior they have had before 3.13; without that,class Fields(ast.AST): _fields = ('a',)raisesTypeError: Field 'a' is missing from Fields._field_types.Lib/test/test_ast/test_ast.pygets a test checking that every class in theastmodule has a_field_typesdictionary whose keys match_fields, andtest_fields_but_no_field_typescovers the subclass behavior above.test_astpasses, also with-R 3:3ast.class._field_typescauses Exception whenast.class._fieldsdoes not cause Exception #135797