Skip to content

Commit eec8e61

Browse files
authored
bpo-43244: Remove the PyAST_Validate() function (GH-24911)
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). Rename PyAST_Validate() function to _PyAST_Validate(), move it to the internal C API, and don't export it anymore (replace PyAPI_FUNC with extern). The function was added in bpo-12575 by the commit 832bfe2.
1 parent fc980e0 commit eec8e61

File tree

7 files changed

+15
-5
lines changed

7 files changed

+15
-5
lines changed

Doc/whatsnew/3.10.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,3 +1353,8 @@ Removed
13531353
Python already implicitly installs signal handlers: see
13541354
:c:member:`PyConfig.install_signal_handlers`.
13551355
(Contributed by Victor Stinner in :issue:`41713`.)
1356+
1357+
* Remove the ``PyAST_Validate()`` function. It is no longer possible to build a
1358+
AST object (``mod_ty`` type) with the public C API. The function was already
1359+
excluded from the limited C API (:pep:`384`).
1360+
(Contributed by Victor Stinner in :issue:`43244`.)

Include/ast.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ extern "C" {
77

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

10-
PyAPI_FUNC(int) PyAST_Validate(mod_ty);
11-
1210
#ifdef __cplusplus
1311
}
1412
#endif

Include/internal/pycore_ast.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ extern "C" {
1010

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

13+
extern int _PyAST_Validate(mod_ty);
14+
1315
/* _PyAST_ExprAsUnicode is defined in ast_unparse.c */
1416
extern PyObject* _PyAST_ExprAsUnicode(expr_ty);
1517

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Remove the ``PyAST_Validate()`` function. It is no longer possible to build a
2+
AST object (``mod_ty`` type) with the public C API. The function was already
3+
excluded from the limited C API (:pep:`384`). Patch by Victor Stinner.

Parser/pegen.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <Python.h>
2+
#include "pycore_ast.h" // _PyAST_Validate()
23
#include <errcode.h>
34
#include "tokenizer.h"
45

@@ -1271,7 +1272,7 @@ _PyPegen_run_parser(Parser *p)
12711272
p->start_rule == Py_file_input ||
12721273
p->start_rule == Py_eval_input)
12731274
{
1274-
if (!PyAST_Validate(res)) {
1275+
if (!_PyAST_Validate(res)) {
12751276
return NULL;
12761277
}
12771278
}

Python/ast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ validate_exprs(asdl_expr_seq *exprs, expr_context_ty ctx, int null_ok)
551551
}
552552

553553
int
554-
PyAST_Validate(mod_ty mod)
554+
_PyAST_Validate(mod_ty mod)
555555
{
556556
int res = 0;
557557

Python/bltinmodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <ctype.h>
55
#include "ast.h"
66
#undef Yield /* undefine macro conflicting with <winbase.h> */
7+
#include "pycore_ast.h" // _PyAST_Validate()
78
#include "pycore_object.h" // _Py_AddToAllObjects()
89
#include "pycore_pyerrors.h" // _PyErr_NoMemory()
910
#include "pycore_pystate.h" // _PyThreadState_GET()
@@ -835,7 +836,7 @@ builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
835836
PyArena_Free(arena);
836837
goto error;
837838
}
838-
if (!PyAST_Validate(mod)) {
839+
if (!_PyAST_Validate(mod)) {
839840
PyArena_Free(arena);
840841
goto error;
841842
}

0 commit comments

Comments
 (0)