GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-135797: Add _field_types to abstract AST classes by Wojusensei · Pull Request #159567 · python/cpython

Conversation

@Wojusensei

@Wojusensei Wojusensei commented Oct 16, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Classes without fields have always had an empty _fields tuple, but they 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

the constructor used the missing attribute to tell user subclasses that declare _fields but no _field_types apart 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',) raises TypeError: Field 'a' is missing from Fields._field_types.

Lib/test/test_ast/test_ast.py gets a test checking that every class in the ast module has a _field_types dictionary whose keys match _fields, and test_fields_but_no_field_types covers the subclass behavior above. test_ast passes, also with -R 3:3

  • Issue: ast.class._field_types causes Exception when ast.class._fields does not cause Exception #135797

ps:

the decision in gh-135797 was made when python3.15 was still the default branch; py3.15 has since branched, so this lands in py3.16 as the default-branch-only change it called for

and replaces gh-135800 which was closed after its author asked for someone else to finish it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Wojusensei
Wojusensei requested review from Eclips4, lysnikolaou, pablogsal and tomasr8 as code owners October 16, 2026 19:18
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 16, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Oct 16, 2026
ast.class._field_types causes Exception when ast.class._fields does not cause Exception #135797
Open
@bedevere-app bedevere-app Bot added the awaiting review label Oct 16, 2026
@read-the-docs-community

read-the-docs-community Bot commented Oct 16, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35204027 | 📁 Comparing 711a776 against main (d3ada45)

  🔍 Preview build  

4 files changed
± library/ast.html
± library/calendar.html
± library/test.html
± whatsnew/changelog.html
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Wojusensei
pythongh-135797: Add _field_types to abstract AST classes
711a776
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.
@Wojusensei
Wojusensei force-pushed the gh-135797 branch from 32f6da7 to 711a776 Compare October 17, 2026 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@pablogsal pablogsal Awaiting requested review from pablogsal pablogsal is a code owner
@lysnikolaou lysnikolaou Awaiting requested review from lysnikolaou lysnikolaou is a code owner
@Eclips4 Eclips4 Awaiting requested review from Eclips4 Eclips4 is a code owner
@tomasr8 tomasr8 Awaiting requested review from tomasr8 tomasr8 is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review type-feature A feature request or enhancement

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@Wojusensei
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.