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 — bpo-43244: Remove ast.h, asdl.h, Python-ast.h headers by vstinner · Pull Request #24933 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Mar 19, 2021 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

These fuctions were undocumented and excluded from the limited C API.

Most names defined by these header files were not prefixed by "Py"
and so could create names conflicts. For example, Python-ast.h
defined a "Yield" macro which was conflict with the "Yield" name used
by the Windows <winbase.h> header.

Use the Python ast module instead.

  • Move Include/asdl.h to Include/internal/pycore_asdl.h.
  • Move Include/Python-ast.h to Include/internal/pycore_ast.h.
  • Remove ast.h header file.
  • pycore_symtable.h no longer includes Python-ast.h.

https://bugs.python.org/issue43244

Sorry, something went wrong.

Uh oh!

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

All reactions
@vstinner
vstinner requested review from a team, brettcannon, encukou, ericsnowcurrently, isidentical, lysnikolaou, ncoghlan, pablogsal and warsaw as code owners March 19, 2021 12:35
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Mar 19, 2021
@bedevere-bot bedevere-bot added the awaiting core review label Mar 19, 2021
@vstinner

vstinner commented Mar 19, 2021

Copy link
Copy Markdown
Member Author

I searched for asdl.h in the top PyPI 4000 projects, I found 3 projects using it: 2 can be ignored, the only interesting one is typed_ast. IMO typed_ast should not block this PR.

typed_ast-1.4.2.tar.gz: this project contains copies of C and header files of CPython.

ast3/Include/Python-ast.h
ast3/Include/asdl.h
ast3/Include/ast.h
ast3/Include/bitset.h
ast3/Include/errcode.h
ast3/Include/graminit.h
ast3/Include/grammar.h
ast3/Include/node.h
ast3/Include/parsetok.h
ast3/Include/pgenheaders.h
ast3/Include/token.h
ast3/Parser/acceler.c
ast3/Parser/bitset.c
ast3/Parser/grammar.c
ast3/Parser/grammar1.c
ast3/Parser/node.c
ast3/Parser/parser.c
ast3/Parser/parser.h
ast3/Parser/parsetok.c
ast3/Parser/tokenizer.c
ast3/Parser/tokenizer.h
ast3/Python/Python-ast.c
ast3/Python/asdl.c
ast3/Python/ast.c
ast3/Python/graminit.c

This project can be modified to copy Python 3.10 internal header files and be built with Py_BUILD_CORE_MODULE macro defined.

Pygments-2.8.0.tar.gz: it's used in example files to test the project, these files are not built, Pygments colorizes text files.

./tests/examplefiles/make/Makefile:		Include/asdl.h \
./tests/examplefiles/make/Makefile.output:'Include/asdl.h' Text

odfpy-1.4.1.tar.gz: the tarball contains many virtual environment in an hidden .tox/ subdirectory.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Mar 19, 2021

Copy link
Copy Markdown
Member Author

I searched for ast.h using \bast\.h\b regex and for Python-ast.h in the top PyPI 4000 projects, I found:

  • the 3 same projects than when I search for asdl.h (typed_ast, Pygments, odfpy)
  • jsonnet which contains its own ast.h file: core/ast.h

In short, in the 4000 projects, typed_ast should be the only project impacted by this PR.

typed_ast copies/paste code directly from CPython, so I'm not surprised that it's impacted by changes in the CPython ASDL and AST implementation :-) typed_ast can continue copying code from CPython, but may need to be built with Py_BUILD_CORE_MODULE macro defined.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Mar 19, 2021

Copy link
Copy Markdown
Member Author

Ah, test_asyncio failed on the Windows x64 CI, known random test failure: https://bugs.python.org/issue43539

All reactions

Sorry, something went wrong.

Uh oh!

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

@pablogsal
pablogsal requested a review from gvanrossum March 19, 2021 12:59
vstinner
vstinner commented Mar 19, 2021
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member 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.

pycore_ast.h now contains definitions of functions defined in Python-ast.c and in ast.c. Is that a good thing, or do you prefer to keep two header files separated? I failed to find a better name of the generated header file (old Python-ast.h).

Sorry, something went wrong.

Uh oh!

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

All reactions
@shihai1991

shihai1991 commented Mar 20, 2021

Copy link
Copy Markdown
Member

pycore_ast.h now contains definitions of functions defined in Python-ast.c and in ast.c. Is that a good thing, or do you prefer to keep two header files separated? I failed to find a better name of the generated header file (old Python-ast.h).

Hm, Can we merge pycore_ast_state.h in pycore_ast.h? There just only have a ast_state in pycore_ast_state.h.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Mar 20, 2021

Copy link
Copy Markdown
Member Author

Hm, Can we merge pycore_ast_state.h in pycore_ast.h? There just only have a ast_state in pycore_ast_state.h.

Yes, but I would prefer to not do that.

pycore_ast_state.h is included by pycore_interp.h and this header file is included by many C files. I would prefer to avoid including pycore_ast.h in C files since this header file is problematic, for example it requires #undef Yield to avoid conflict with <winbase.h>.

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

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Mar 22, 2021

Copy link
Copy Markdown
Member Author

PR rebased on master to fix a conflict on compile.h.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Mar 22, 2021

Copy link
Copy Markdown
Member Author

Removed functions are undocumented. They are also excluded from the limited C API (and from the stable ABI).

I updated the PR to mention that explicitly.

I cannot find removed functions in Doc/c-api/:

  • asdl.h: asdl
  • Python-ast.h: PyAST_obj2mod, PyAST_Check, PyAST_mod2obj, _Py_Module, mod_ty
  • ast.h: PyAST_Validate, PyAST_FromNode, PyAST_FromNodeObject, _PyAST_ExprAsUnicode, _PyAST_GetDocString
All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner
bpo-43244: Remove ast.h, asdl.h, Python-ast.h headers
4c68ac5
These functions were undocumented and excluded from the limited C
API.

Most names defined by these header files were not prefixed by "Py"
and so could create names conflicts. For example, Python-ast.h
defined a "Yield" macro which was conflict with the "Yield" name used
by the Windows <winbase.h> header.

Use the Python ast module instead.

* Move Include/asdl.h to Include/internal/pycore_asdl.h.
* Move Include/Python-ast.h to Include/internal/pycore_ast.h.
* Remove ast.h header file.
* pycore_symtable.h no longer includes Python-ast.h.
@vstinner

vstinner commented Mar 23, 2021

Copy link
Copy Markdown
Member Author

Oops, I fixed a typo: fuctions => functions.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner
vstinner merged commit 94faa07 into python:master Mar 23, 2021
@bedevere-bot bedevere-bot removed the awaiting core review label Mar 23, 2021
@vstinner
vstinner deleted the internal_pycore_ast branch March 23, 2021 19:47
@vstinner vstinner mentioned this pull request Mar 23, 2021
bpo-43244: Add pycore_compile.h header file #25000
Merged
@ezio-melotti ezio-melotti mentioned this pull request Nov 14, 2022
Use :cpy-file: throughout the Devguide python/devguide#984
Merged
@ezio-melotti ezio-melotti mentioned this pull request Dec 9, 2022
Fix links to missing CPython files python/devguide#1003
Open
@hugovk hugovk mentioned this pull request Feb 21, 2026
Remove unused size.py and refs to removed CPython files python/release-tools#343
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@brettcannon brettcannon Awaiting requested review from brettcannon
@encukou encukou Awaiting requested review from encukou
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently
@isidentical isidentical Awaiting requested review from isidentical
@lysnikolaou lysnikolaou Awaiting requested review from lysnikolaou
@ncoghlan ncoghlan Awaiting requested review from ncoghlan
@pablogsal pablogsal Awaiting requested review from pablogsal
@warsaw warsaw Awaiting requested review from warsaw
@gvanrossum gvanrossum Awaiting requested review from gvanrossum

Uh oh!

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

Assignees

No one assigned

Labels

None yet

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

@vstinner @shihai1991 @the-knights-who-say-ni @bedevere-bot
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.