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-116021: Deprecate support for instantiating abstract AST nodes by brianschubert · Pull Request #137865 · python/cpython

Conversation

@brianschubert

@brianschubert brianschubert commented Aug 16, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Demonstration:

>>> ast.stmt()
<python-input-1>:1: DeprecationWarning: Instantiating abstract AST node class ast.stmt is deprecated. This will become an error in Python 3.20
stmt()

>>> class MyStmt(ast.stmt): pass
... 
>>> MyStmt()
MyStmt()

This tracks which AST nodes are abstract using an internal set that gets built during node type initialization. I tried a few different approaches, and this seemed the simplest. A nice thing about this approach is that the check for abstract-ness depends on the exact node type, so this avoids most inheritance subtleties that could interfere with existing user-defined subclasses.

  • Issue: Deprecate creation of abstract AST nodes #116021

📚 Documentation preview 📚: https://cpython-previews--137865.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

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

All reactions
@brianschubert
Deprecate support for instantiating abstract AST nodes
1b767fc
@brianschubert
brianschubert requested review from AA-Turner, Eclips4, JelleZijlstra, ericsnowcurrently, isidentical and tomasr8 as code owners August 16, 2025 17:39
@bedevere-app bedevere-app Bot added the awaiting review label Aug 16, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Aug 16, 2025
Deprecate creation of abstract AST nodes #116021
Closed
brianschubert added 2 commits August 16, 2025 13:52
@brianschubert
Missing static
b72a362
@brianschubert
Capture warning in test_sys
c8dda97
brianschubert
brianschubert commented Aug 16, 2025
View reviewed changes
Comment thread Lib/test/test_sys.py Outdated
Comment on lines +1880 to +1881
check(_ast.AST(), size('P'))
with self.assertWarns(DeprecationWarning):
check(_ast.AST(), size('P'))

@brianschubert brianschubert Aug 16, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should probably be rewritten, but I'm not sure I understand the goal of this test well enough to do that. Suggestions welcome!

Sorry, something went wrong.

Uh oh!

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

All reactions

@picnixz picnixz Aug 18, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's to check that objects in Python/ have the correct types. I don't know why it's actually in test_sys though. I think we should split this test and move each check to the module it belongs (ast.AST's size should be checked in test_ast).

For now, leave it here. A separate issue should be opened.

Sorry, something went wrong.

Uh oh!

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

brianschubert reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@JelleZijlstra JelleZijlstra Oct 20, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's here because it's arguably testing sys.getsizeof. Maybe it could be changed to test a concrete AST class instead?

Sorry, something went wrong.

Uh oh!

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

All reactions

@brianschubert brianschubert Oct 27, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check(_ast.Module(), size('3P')) might work then? (not sure if I'm counting the object size right)

Sorry, something went wrong.

Uh oh!

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

All reactions

@brianschubert brianschubert Nov 29, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JelleZijlstra @picnixz any further thoughts re: above? Happy to update this is someone can confirm a good substitute

Sorry, something went wrong.

Uh oh!

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

All reactions

@JelleZijlstra JelleZijlstra Dec 2, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, what you suggest should work (haven't verified the object size is right).

Sorry, something went wrong.

Uh oh!

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

brianschubert reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@brianschubert brianschubert Feb 22, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking again 3P seems right, updated!

Sorry, something went wrong.

Uh oh!

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

All reactions
picnixz
picnixz reviewed Aug 18, 2025
View reviewed changes

@picnixz picnixz left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be easier to have a module function checking if a node is abstract? say _ast.is_abstract(node) (in the C module, not the Python module). That way we don't need an additional method on AST objects (which could be shadowed).

Sorry, something went wrong.

Uh oh!

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

brianschubert reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Lib/test/test_sys.py Outdated
Comment on lines +1880 to +1881
check(_ast.AST(), size('P'))
with self.assertWarns(DeprecationWarning):
check(_ast.AST(), size('P'))

@picnixz picnixz Aug 18, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's to check that objects in Python/ have the correct types. I don't know why it's actually in test_sys though. I think we should split this test and move each check to the module it belongs (ast.AST's size should be checked in test_ast).

For now, leave it here. A separate issue should be opened.

Sorry, something went wrong.

Uh oh!

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

brianschubert reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Parser/asdl_c.py Resolved

Uh oh!

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

Comment thread Parser/asdl_c.py Outdated
return result;
}

/* Helper for checking if a node class is abstract in the tests. */

@picnixz picnixz Aug 18, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use clinic here, but this would create a new file as we don't use it at all. Maybe we can do it in a follow-up PR though.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Parser/asdl_c.py Resolved

Uh oh!

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

Comment thread Lib/test/test_ast/test_ast.py Resolved

Uh oh!

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

Comment thread Lib/test/test_ast/test_ast.py Resolved

Uh oh!

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

Comment thread Lib/test/test_ast/test_ast.py Resolved

Uh oh!

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

Comment thread Lib/test/test_ast/test_ast.py Resolved

Uh oh!

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

Comment thread Lib/test/test_ast/test_ast.py Resolved

Uh oh!

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

brianschubert and others added 3 commits August 18, 2025 17:06
@brianschubert @picnixz
Convert _is_abstract to module function, address misc review comments
e550c2a
Co-authored-by: Bénédikt Tran <[email protected]>
@brianschubert
Retarget removal for Python 3.19
90b7428
3.14 + 5 = 3.19
@brianschubert
Add pending-removal-in-3.19.rst mention
16db374
@brianschubert
brianschubert requested review from lysnikolaou and pablogsal as code owners September 8, 2025 21:29
brianschubert added 3 commits September 14, 2025 19:27
@brianschubert
Merge branch 'main' into pythongh-116021-ast-depr-abstract
2f390c8
@brianschubert
Merge branch 'main' into pythongh-116021-ast-depr-abstract
97dbdab
@brianschubert
Retarget removal for Python 3.20
66586e7
JelleZijlstra
JelleZijlstra approved these changes Oct 20, 2025
View reviewed changes
Comment thread Lib/test/test_sys.py Outdated
Comment on lines +1880 to +1881
check(_ast.AST(), size('P'))
with self.assertWarns(DeprecationWarning):
check(_ast.AST(), size('P'))

@JelleZijlstra JelleZijlstra Oct 20, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's here because it's arguably testing sys.getsizeof. Maybe it could be changed to test a concrete AST class instead?

Sorry, something went wrong.

Uh oh!

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

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Oct 20, 2025
brianschubert added 4 commits October 26, 2025 21:10
@brianschubert
Merge remote-tracking branch 'upstream/main'
250c33c
@brianschubert
Merge branch 'main' into pythongh-116021-ast-depr-abstract
f8c0aef
@brianschubert
Merge branch 'main'
b4ef16b
@brianschubert
Update test_sys per review
adcacdd
@brianschubert
brianschubert requested review from JelleZijlstra and picnixz February 22, 2026 21:15
JelleZijlstra
JelleZijlstra reviewed Feb 22, 2026
View reviewed changes
Comment thread Parser/asdl_c.py Resolved

Uh oh!

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

JelleZijlstra
JelleZijlstra approved these changes Feb 22, 2026
View reviewed changes
brianschubert and others added 2 commits February 22, 2026 17:20
@brianschubert @JelleZijlstra
Update Parser/asdl_c.py
b7100a4
Co-authored-by: Jelle Zijlstra <[email protected]>
@brianschubert
Regen Python-ast.c
202a372
Eclips4
Eclips4 approved these changes Mar 1, 2026
View reviewed changes
@github-actions

github-actions Bot commented Apr 28, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

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

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 28, 2026
@brianschubert
Merge branch 'main' into pythongh-116021-ast-depr-abstract
0eb074e
@JelleZijlstra
JelleZijlstra merged commit bdedc4a into python:main May 2, 2026
98 of 100 checks passed

Uh oh!

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

@bedevere-app bedevere-app Bot removed the awaiting merge label May 2, 2026
@newville newville mentioned this pull request Oct 2, 2026
Python 3.15 checks and updates lmfit/asteval#159
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@JelleZijlstra JelleZijlstra JelleZijlstra approved these changes
@Eclips4 Eclips4 Eclips4 approved these changes
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner
@tomasr8 tomasr8 Awaiting requested review from tomasr8 tomasr8 is a code owner
@isidentical isidentical Awaiting requested review from isidentical
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner
@pablogsal pablogsal Awaiting requested review from pablogsal pablogsal is a code owner
@lysnikolaou lysnikolaou Awaiting requested review from lysnikolaou lysnikolaou is a code owner
@picnixz picnixz Awaiting requested review from picnixz

Uh oh!

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

Assignees

No one assigned

Labels

stale Stale PR or inactive for long period of time.

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.

4 participants

@brianschubert @JelleZijlstra @picnixz @Eclips4
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 01402520 — 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.