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-41194: Convert _ast extension to PEP 489 by vstinner · Pull Request #21293 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Jul 3, 2020 •
edited by bedevere-bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

Convert the _ast extension module to PEP 489 "Multiphase
initialization". Replace the global _ast state with a module state.

https://bugs.python.org/issue41194

Sorry, something went wrong.

Uh oh!

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

All reactions
@vstinner
bpo-41194: Convert _ast extension to PEP 489
df287d4
Convert the _ast extension module to PEP 489 "Multiphase
initialization". Replace the global _ast state with a module state.
@vstinner
vstinner requested review from lysnikolaou and pablogsal as code owners July 3, 2020 12:19
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Jul 3, 2020
@bedevere-bot bedevere-bot added the awaiting core review label Jul 3, 2020
@vstinner

vstinner commented Jul 3, 2020

Copy link
Copy Markdown
Member Author

With this PR, get_global_ast_state() is still used by multiple functions. It can introduce minor inconsistencies when the _ast extension module is loaded more than once in the same interpreter. But this PR better isolates the _ast module in subinterpreters.

The PyType_GetModule() (PEP 573) cannot be used in ast_type_init() (tp_init slot).

Even if all AST_Type methods and slots are fixed to use PyType_GetModule(), there are still PyAST_mod2obj() and PyAST_obj2mod() functions which still use get_global_ast_state().

Even if get_global_ast_state() has drawbacks, IMHO this PR is worth it.

@corona10: Would you mind to review it?

cc @DinoV

corona10 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 added the skip news label Jul 3, 2020
corona10
corona10 approved these changes Jul 3, 2020
View reviewed changes

@corona10 corona10 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.

Looks good with a simple question :)

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.

@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels Jul 3, 2020
@vstinner
astmodule_exec(): return -1 on error
7b1921b
@vstinner

vstinner commented Jul 3, 2020

Copy link
Copy Markdown
Member Author

continuous-integration/travis-ci Expected — Waiting for status to be reported

But https://travis-ci.org/github/python/cpython/builds/704696576 is the build and it completed. I don't get it :-(

  • Ran for 18 min 13 sec
  • Total time 27 min 27 sec
  • 9 minutes ago
All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner vstinner closed this Jul 3, 2020
@vstinner vstinner reopened this Jul 3, 2020
@vstinner

vstinner commented Jul 3, 2020

Copy link
Copy Markdown
Member Author

I close/reopen my issue to force a new Travis CI build :-(

corona10 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.

@corona10

corona10 commented Jul 3, 2020

Copy link
Copy Markdown
Member

I did same thing on #21294 :(

All reactions

Sorry, something went wrong.

Uh oh!

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

@corona10 corona10 closed this Jul 3, 2020
@corona10 corona10 reopened this Jul 3, 2020
@corona10

corona10 commented Jul 3, 2020

Copy link
Copy Markdown
Member

re-open :)

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner
vstinner merged commit b1cc6ba into python:master Jul 3, 2020
@bedevere-bot bedevere-bot removed the awaiting merge label Jul 3, 2020
@vstinner
vstinner deleted the ast_module_state branch July 3, 2020 18:01
vstinner added a commit that referenced this pull request Aug 10, 2020
@vstinner
[3.9] bpo-41194: Convert _ast extension to PEP 489 (GH-21807)
d2bea26
* bpo-41194: Convert _ast extension to PEP 489 (GH-21293)

Convert the _ast extension module to PEP 489 "Multiphase
initialization". Replace the global _ast state with a module state.

(cherry picked from commit b1cc6ba)

* bpo-41204: Fix compiler warning in ast_type_init() (GH-21307)

(cherry picked from commit 1f76453)
encukou
encukou reviewed Aug 25, 2020
View reviewed changes
Comment thread Parser/asdl_c.py
if (name == NULL) {
return NULL;
}
PyObject *module = PyImport_GetModule(name);

@encukou encukou Aug 25, 2020

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.

As noted in https://bugs.python.org/issue41631, this is incorrect :(
PyImport_GetModule looks in sys.modules, which is modifiable by the user, and so it's not guaranteed to return _ast.

Sorry, something went wrong.

Uh oh!

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

All reactions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@encukou encukou encukou left review comments
@corona10 corona10 corona10 approved these changes
@lysnikolaou lysnikolaou Awaiting requested review from lysnikolaou
@pablogsal pablogsal Awaiting requested review from pablogsal

Uh oh!

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

Assignees

No one assigned

Labels

skip news

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.

5 participants

@vstinner @corona10 @encukou @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 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.