Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 30704ea

Browse files
committed
Remove "ast" aliases from the parser module.
1 parent 4dcce17 commit 30704ea

3 files changed

Lines changed: 17 additions & 32 deletions

File tree

Doc/library/parser.rst

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ the code forming the application. It is also faster.
3030
Syntax Tree (AST) generation and compilation stage, using the :mod:`ast`
3131
module.
3232

33-
The :mod:`parser` module exports the names documented here also with "st"
34-
replaced by "ast"; this is a legacy from the time when there was no other
35-
AST and has nothing to do with the AST found in Python 2.5. This is also the
36-
reason for the functions' keyword arguments being called *ast*, not *st*.
37-
3833
There are a few things to note about this module which are important to making
3934
use of the data structures created. This is not a tutorial on editing the parse
4035
trees for Python code, but some examples of using the :mod:`parser` module are
@@ -170,9 +165,9 @@ executable code objects. Parse trees may be extracted with or without line
170165
numbering information.
171166

172167

173-
.. function:: st2list(ast[, line_info])
168+
.. function:: st2list(st[, line_info])
174169

175-
This function accepts an ST object from the caller in *ast* and returns a
170+
This function accepts an ST object from the caller in *st* and returns a
176171
Python list representing the equivalent parse tree. The resulting list
177172
representation can be used for inspection or the creation of a new parse tree in
178173
list form. This function does not fail so long as memory is available to build
@@ -188,9 +183,9 @@ numbering information.
188183
This information is omitted if the flag is false or omitted.
189184

190185

191-
.. function:: st2tuple(ast[, line_info])
186+
.. function:: st2tuple(st[, line_info])
192187

193-
This function accepts an ST object from the caller in *ast* and returns a
188+
This function accepts an ST object from the caller in *st* and returns a
194189
Python tuple representing the equivalent parse tree. Other than returning a
195190
tuple instead of a list, this function is identical to :func:`st2list`.
196191

@@ -199,7 +194,7 @@ numbering information.
199194
information is omitted if the flag is false or omitted.
200195

201196

202-
.. function:: compilest(ast[, filename='<syntax-tree>'])
197+
.. function:: compilest(st[, filename='<syntax-tree>'])
203198

204199
.. index::
205200
builtin: exec
@@ -208,7 +203,7 @@ numbering information.
208203
The Python byte compiler can be invoked on an ST object to produce code objects
209204
which can be used as part of a call to the built-in :func:`exec` or :func:`eval`
210205
functions. This function provides the interface to the compiler, passing the
211-
internal parse tree from *ast* to the parser, using the source file name
206+
internal parse tree from *st* to the parser, using the source file name
212207
specified by the *filename* parameter. The default value supplied for *filename*
213208
indicates that the source was an ST object.
214209

@@ -233,22 +228,22 @@ determine if an ST was created from source code via :func:`expr` or
233228
:func:`suite` or from a parse tree via :func:`sequence2st`.
234229

235230

236-
.. function:: isexpr(ast)
231+
.. function:: isexpr(st)
237232

238233
.. index:: builtin: compile
239234

240-
When *ast* represents an ``'eval'`` form, this function returns true, otherwise
235+
When *st* represents an ``'eval'`` form, this function returns true, otherwise
241236
it returns false. This is useful, since code objects normally cannot be queried
242237
for this information using existing built-in functions. Note that the code
243238
objects created by :func:`compilest` cannot be queried like this either, and
244239
are identical to those created by the built-in :func:`compile` function.
245240

246241

247-
.. function:: issuite(ast)
242+
.. function:: issuite(st)
248243

249244
This function mirrors :func:`isexpr` in that it reports whether an ST object
250245
represents an ``'exec'`` form, commonly known as a "suite." It is not safe to
251-
assume that this function is equivalent to ``not isexpr(ast)``, as additional
246+
assume that this function is equivalent to ``not isexpr(st)``, as additional
252247
syntactic fragments may be supported in the future.
253248

254249

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Core and Builtins
3434
Library
3535
-------
3636

37+
- Removed "ast" function aliases from the parser module.
38+
3739
- Issue #3313: Fixed a crash when a failed dlopen() call does not set
3840
a valid dlerror() message.
3941

Modules/parsermodule.c

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ parser_st2tuple(PyST_Object *self, PyObject *args, PyObject *kw)
322322
PyObject *res = 0;
323323
int ok;
324324

325-
static char *keywords[] = {"ast", "line_info", "col_info", NULL};
325+
static char *keywords[] = {"st", "line_info", "col_info", NULL};
326326

327327
if (self == NULL || PyModule_Check(self)) {
328328
ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|OO:st2tuple", keywords,
@@ -366,7 +366,7 @@ parser_st2list(PyST_Object *self, PyObject *args, PyObject *kw)
366366
PyObject *res = 0;
367367
int ok;
368368

369-
static char *keywords[] = {"ast", "line_info", "col_info", NULL};
369+
static char *keywords[] = {"st", "line_info", "col_info", NULL};
370370

371371
if (self == NULL || PyModule_Check(self))
372372
ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|OO:st2list", keywords,
@@ -408,7 +408,7 @@ parser_compilest(PyST_Object *self, PyObject *args, PyObject *kw)
408408
char* str = "<syntax-tree>";
409409
int ok;
410410

411-
static char *keywords[] = {"ast", "filename", NULL};
411+
static char *keywords[] = {"st", "filename", NULL};
412412

413413
if (self == NULL || PyModule_Check(self))
414414
ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|s:compilest", keywords,
@@ -437,7 +437,7 @@ parser_isexpr(PyST_Object *self, PyObject *args, PyObject *kw)
437437
PyObject* res = 0;
438438
int ok;
439439

440-
static char *keywords[] = {"ast", NULL};
440+
static char *keywords[] = {"st", NULL};
441441

442442
if (self == NULL || PyModule_Check(self))
443443
ok = PyArg_ParseTupleAndKeywords(args, kw, "O!:isexpr", keywords,
@@ -460,7 +460,7 @@ parser_issuite(PyST_Object *self, PyObject *args, PyObject *kw)
460460
PyObject* res = 0;
461461
int ok;
462462

463-
static char *keywords[] = {"ast", NULL};
463+
static char *keywords[] = {"st", NULL};
464464

465465
if (self == NULL || PyModule_Check(self))
466466
ok = PyArg_ParseTupleAndKeywords(args, kw, "O!:issuite", keywords,
@@ -3011,12 +3011,6 @@ parser__pickler(PyObject *self, PyObject *args)
30113011
* inheritance.
30123012
*/
30133013
static PyMethodDef parser_functions[] = {
3014-
{"ast2tuple", (PyCFunction)parser_st2tuple, PUBLIC_METHOD_TYPE,
3015-
PyDoc_STR("Creates a tuple-tree representation of an ST.")},
3016-
{"ast2list", (PyCFunction)parser_st2list, PUBLIC_METHOD_TYPE,
3017-
PyDoc_STR("Creates a list-tree representation of an ST.")},
3018-
{"compileast", (PyCFunction)parser_compilest, PUBLIC_METHOD_TYPE,
3019-
PyDoc_STR("Compiles an ST object into a code object.")},
30203014
{"compilest", (PyCFunction)parser_compilest, PUBLIC_METHOD_TYPE,
30213015
PyDoc_STR("Compiles an ST object into a code object.")},
30223016
{"expr", (PyCFunction)parser_expr, PUBLIC_METHOD_TYPE,
@@ -3027,16 +3021,12 @@ static PyMethodDef parser_functions[] = {
30273021
PyDoc_STR("Determines if an ST object was created from a suite.")},
30283022
{"suite", (PyCFunction)parser_suite, PUBLIC_METHOD_TYPE,
30293023
PyDoc_STR("Creates an ST object from a suite.")},
3030-
{"sequence2ast", (PyCFunction)parser_tuple2st, PUBLIC_METHOD_TYPE,
3031-
PyDoc_STR("Creates an ST object from a tree representation.")},
30323024
{"sequence2st", (PyCFunction)parser_tuple2st, PUBLIC_METHOD_TYPE,
30333025
PyDoc_STR("Creates an ST object from a tree representation.")},
30343026
{"st2tuple", (PyCFunction)parser_st2tuple, PUBLIC_METHOD_TYPE,
30353027
PyDoc_STR("Creates a tuple-tree representation of an ST.")},
30363028
{"st2list", (PyCFunction)parser_st2list, PUBLIC_METHOD_TYPE,
30373029
PyDoc_STR("Creates a list-tree representation of an ST.")},
3038-
{"tuple2ast", (PyCFunction)parser_tuple2st, PUBLIC_METHOD_TYPE,
3039-
PyDoc_STR("Creates an ST object from a tree representation.")},
30403030
{"tuple2st", (PyCFunction)parser_tuple2st, PUBLIC_METHOD_TYPE,
30413031
PyDoc_STR("Creates an ST object from a tree representation.")},
30423032

@@ -3089,8 +3079,6 @@ PyInit_parser(void)
30893079
if (PyModule_AddObject(module, "ParserError", parser_error) != 0)
30903080
return NULL;
30913081

3092-
Py_INCREF(&PyST_Type);
3093-
PyModule_AddObject(module, "ASTType", (PyObject*)&PyST_Type);
30943082
Py_INCREF(&PyST_Type);
30953083
PyModule_AddObject(module, "STType", (PyObject*)&PyST_Type);
30963084

0 commit comments

Comments
 (0)