Skip to content
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-43244: Remove PyAST_Validate() function #24911

Merged
merged 1 commit into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1353,3 +1353,8 @@ Removed
Python already implicitly installs signal handlers: see
:c:member:`PyConfig.install_signal_handlers`.
(Contributed by Victor Stinner in :issue:`41713`.)

* Remove the ``PyAST_Validate()`` function. It is no longer possible to build a
AST object (``mod_ty`` type) with the public C API. The function was already
excluded from the limited C API (:pep:`384`).
Copy link
Member

Choose a reason for hiding this comment

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

Hm, pep-384 doesn't mention the ast.h. Can we move the capi directly when this C API is not a limited C API?

Copy link
Member Author

Choose a reason for hiding this comment

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

I just mentioned PEP 384 to explain what is the limited C API.

PyAST_Validate() definition is inside:

#ifndef Py_LIMITED_API
...
#endif /* !Py_LIMITED_API */

Copy link
Member Author

Choose a reason for hiding this comment

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

"Can we move the capi directly when this C API is not a limited C API?" No. I only removed the function since it cannot be used anymore since Python 3.10: " It is no longer possible to build a AST object (mod_ty type) with the public C API."

Copy link
Member

Choose a reason for hiding this comment

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

OK, Thanks. got it.

(Contributed by Victor Stinner in :issue:`43244`.)
2 changes: 0 additions & 2 deletions Include/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ extern "C" {

#include "Python-ast.h" /* mod_ty */

PyAPI_FUNC(int) PyAST_Validate(mod_ty);

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions Include/internal/pycore_ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ extern "C" {

#include "Python-ast.h" // expr_ty

extern int _PyAST_Validate(mod_ty);

/* _PyAST_ExprAsUnicode is defined in ast_unparse.c */
extern PyObject* _PyAST_ExprAsUnicode(expr_ty);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Remove the ``PyAST_Validate()`` function. It is no longer possible to build a
AST object (``mod_ty`` type) with the public C API. The function was already
excluded from the limited C API (:pep:`384`). Patch by Victor Stinner.
3 changes: 2 additions & 1 deletion Parser/pegen.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <Python.h>
#include "pycore_ast.h" // _PyAST_Validate()
#include <errcode.h>
#include "tokenizer.h"

Expand Down Expand Up @@ -1271,7 +1272,7 @@ _PyPegen_run_parser(Parser *p)
p->start_rule == Py_file_input ||
p->start_rule == Py_eval_input)
{
if (!PyAST_Validate(res)) {
if (!_PyAST_Validate(res)) {
return NULL;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Python/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ validate_exprs(asdl_expr_seq *exprs, expr_context_ty ctx, int null_ok)
}

int
PyAST_Validate(mod_ty mod)
_PyAST_Validate(mod_ty mod)
{
int res = 0;

Expand Down
3 changes: 2 additions & 1 deletion Python/bltinmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <ctype.h>
#include "ast.h"
#undef Yield /* undefine macro conflicting with <winbase.h> */
#include "pycore_ast.h" // _PyAST_Validate()
#include "pycore_object.h" // _Py_AddToAllObjects()
#include "pycore_pyerrors.h" // _PyErr_NoMemory()
#include "pycore_pystate.h" // _PyThreadState_GET()
Expand Down Expand Up @@ -835,7 +836,7 @@ builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
PyArena_Free(arena);
goto error;
}
if (!PyAST_Validate(mod)) {
if (!_PyAST_Validate(mod)) {
PyArena_Free(arena);
goto error;
}
Expand Down