-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-38113: Update the Python-ast.c generator to PEP384 #15957
Conversation
Summary: This fully migrates Python-ast.c to PEP384 and removes all statics from the whole file. This modifies the generator itself that generates the Python-ast.c
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.
LGTM
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags:
Parser/asdl_c.py
Outdated
"(PyObject *)%s_type);") | ||
self.emit(line % (t.name,), 1) | ||
self.emit("isinstance = PyObject_IsInstance(obj, " | ||
f"astmodulestate_global->{t.name}_type);", 1) |
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.
You cannot use f-strings here. Some platforms like old Ubuntu have python3 3.5 or older. Travis CI is failing with a SyntaxError.
When you're done making the requested changes, leave the comment: |
self.emit("if (init_identifiers() < 0) return 0;", 1) | ||
self.emit("state->AST_type = PyType_FromSpec(&AST_type_spec);", 1) | ||
self.emit("if (!state->AST_type) return 0;", 1) | ||
self.emit("((PyTypeObject*)state->AST_type)->tp_dictoffset = offsetof(AST_object, dict);", 1) |
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.
This is still accessing the dict offset, we need to remove this by letting the type system handle it
Partially revert commit ac46eb4: "bpo-38113: Update the Python-ast.c generator to PEP384 (gh-15957)". Using a module state per module instance is causing subtle practical problems. For example, the Mercurial project replaces the __import__() function to implement lazy import, whereas Python expected that "import _ast" always return a fully initialized _ast module. Add _PyAST_Fini() to clear the state at exit. The _ast module has no state (set _astmodule.m_size to 0). Remove astmodule_traverse(), astmodule_clear() and astmodule_free() functions.
Partially revert commit ac46eb4: "bpo-38113: Update the Python-ast.c generator to PEP384 (pythongh-15957)". Using a module state per module instance is causing subtle practical problems. For example, the Mercurial project replaces the __import__() function to implement lazy import, whereas Python expected that "import _ast" always return a fully initialized _ast module. Add _PyAST_Fini() to clear the state at exit. The _ast module has no state (set _astmodule.m_size to 0). Remove astmodule_traverse(), astmodule_clear() and astmodule_free() functions.. (cherry picked from commit e5fbe0c) Co-authored-by: Victor Stinner <vstinner@python.org>
…-22258) Partially revert commit ac46eb4: "bpo-38113: Update the Python-ast.c generator to PEP384 (gh-15957)". Using a module state per module instance is causing subtle practical problems. For example, the Mercurial project replaces the __import__() function to implement lazy import, whereas Python expected that "import _ast" always return a fully initialized _ast module. Add _PyAST_Fini() to clear the state at exit. The _ast module has no state (set _astmodule.m_size to 0). Remove astmodule_traverse(), astmodule_clear() and astmodule_free() functions.. (cherry picked from commit e5fbe0c) Co-authored-by: Victor Stinner <vstinner@python.org>
Partially revert commit ac46eb4: "bpo-38113: Update the Python-ast.c generator to PEP384 (pythongh-15957)". Using a module state per module instance is causing subtle practical problems. For example, the Mercurial project replaces the __import__() function to implement lazy import, whereas Python expected that "import _ast" always return a fully initialized _ast module. Add _PyAST_Fini() to clear the state at exit. The _ast module has no state (set _astmodule.m_size to 0). Remove astmodule_traverse(), astmodule_clear() and astmodule_free() functions.
Summary: This mostly migrates Python-ast.c to PEP384 and removes all statics from the whole file. This modifies the generator itself that generates the Python-ast.c. It leaves in the usage of _PyObject_LookupAttr even though it's not fully PEP384 compatible (this could always be shimmed in by anyone who needs it).
https://bugs.python.org/issue38113