mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
Remove "ast" aliases from the parser module.
This commit is contained in:
parent
4dcce175e2
commit
30704ea0db
3 changed files with 17 additions and 32 deletions
|
@ -30,11 +30,6 @@ the code forming the application. It is also faster.
|
||||||
Syntax Tree (AST) generation and compilation stage, using the :mod:`ast`
|
Syntax Tree (AST) generation and compilation stage, using the :mod:`ast`
|
||||||
module.
|
module.
|
||||||
|
|
||||||
The :mod:`parser` module exports the names documented here also with "st"
|
|
||||||
replaced by "ast"; this is a legacy from the time when there was no other
|
|
||||||
AST and has nothing to do with the AST found in Python 2.5. This is also the
|
|
||||||
reason for the functions' keyword arguments being called *ast*, not *st*.
|
|
||||||
|
|
||||||
There are a few things to note about this module which are important to making
|
There are a few things to note about this module which are important to making
|
||||||
use of the data structures created. This is not a tutorial on editing the parse
|
use of the data structures created. This is not a tutorial on editing the parse
|
||||||
trees for Python code, but some examples of using the :mod:`parser` module are
|
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
|
||||||
numbering information.
|
numbering information.
|
||||||
|
|
||||||
|
|
||||||
.. function:: st2list(ast[, line_info])
|
.. function:: st2list(st[, line_info])
|
||||||
|
|
||||||
This function accepts an ST object from the caller in *ast* and returns a
|
This function accepts an ST object from the caller in *st* and returns a
|
||||||
Python list representing the equivalent parse tree. The resulting list
|
Python list representing the equivalent parse tree. The resulting list
|
||||||
representation can be used for inspection or the creation of a new parse tree in
|
representation can be used for inspection or the creation of a new parse tree in
|
||||||
list form. This function does not fail so long as memory is available to build
|
list form. This function does not fail so long as memory is available to build
|
||||||
|
@ -188,9 +183,9 @@ numbering information.
|
||||||
This information is omitted if the flag is false or omitted.
|
This information is omitted if the flag is false or omitted.
|
||||||
|
|
||||||
|
|
||||||
.. function:: st2tuple(ast[, line_info])
|
.. function:: st2tuple(st[, line_info])
|
||||||
|
|
||||||
This function accepts an ST object from the caller in *ast* and returns a
|
This function accepts an ST object from the caller in *st* and returns a
|
||||||
Python tuple representing the equivalent parse tree. Other than returning a
|
Python tuple representing the equivalent parse tree. Other than returning a
|
||||||
tuple instead of a list, this function is identical to :func:`st2list`.
|
tuple instead of a list, this function is identical to :func:`st2list`.
|
||||||
|
|
||||||
|
@ -199,7 +194,7 @@ numbering information.
|
||||||
information is omitted if the flag is false or omitted.
|
information is omitted if the flag is false or omitted.
|
||||||
|
|
||||||
|
|
||||||
.. function:: compilest(ast[, filename='<syntax-tree>'])
|
.. function:: compilest(st[, filename='<syntax-tree>'])
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
builtin: exec
|
builtin: exec
|
||||||
|
@ -208,7 +203,7 @@ numbering information.
|
||||||
The Python byte compiler can be invoked on an ST object to produce code objects
|
The Python byte compiler can be invoked on an ST object to produce code objects
|
||||||
which can be used as part of a call to the built-in :func:`exec` or :func:`eval`
|
which can be used as part of a call to the built-in :func:`exec` or :func:`eval`
|
||||||
functions. This function provides the interface to the compiler, passing the
|
functions. This function provides the interface to the compiler, passing the
|
||||||
internal parse tree from *ast* to the parser, using the source file name
|
internal parse tree from *st* to the parser, using the source file name
|
||||||
specified by the *filename* parameter. The default value supplied for *filename*
|
specified by the *filename* parameter. The default value supplied for *filename*
|
||||||
indicates that the source was an ST object.
|
indicates that the source was an ST object.
|
||||||
|
|
||||||
|
@ -233,22 +228,22 @@ determine if an ST was created from source code via :func:`expr` or
|
||||||
:func:`suite` or from a parse tree via :func:`sequence2st`.
|
:func:`suite` or from a parse tree via :func:`sequence2st`.
|
||||||
|
|
||||||
|
|
||||||
.. function:: isexpr(ast)
|
.. function:: isexpr(st)
|
||||||
|
|
||||||
.. index:: builtin: compile
|
.. index:: builtin: compile
|
||||||
|
|
||||||
When *ast* represents an ``'eval'`` form, this function returns true, otherwise
|
When *st* represents an ``'eval'`` form, this function returns true, otherwise
|
||||||
it returns false. This is useful, since code objects normally cannot be queried
|
it returns false. This is useful, since code objects normally cannot be queried
|
||||||
for this information using existing built-in functions. Note that the code
|
for this information using existing built-in functions. Note that the code
|
||||||
objects created by :func:`compilest` cannot be queried like this either, and
|
objects created by :func:`compilest` cannot be queried like this either, and
|
||||||
are identical to those created by the built-in :func:`compile` function.
|
are identical to those created by the built-in :func:`compile` function.
|
||||||
|
|
||||||
|
|
||||||
.. function:: issuite(ast)
|
.. function:: issuite(st)
|
||||||
|
|
||||||
This function mirrors :func:`isexpr` in that it reports whether an ST object
|
This function mirrors :func:`isexpr` in that it reports whether an ST object
|
||||||
represents an ``'exec'`` form, commonly known as a "suite." It is not safe to
|
represents an ``'exec'`` form, commonly known as a "suite." It is not safe to
|
||||||
assume that this function is equivalent to ``not isexpr(ast)``, as additional
|
assume that this function is equivalent to ``not isexpr(st)``, as additional
|
||||||
syntactic fragments may be supported in the future.
|
syntactic fragments may be supported in the future.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,8 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Removed "ast" function aliases from the parser module.
|
||||||
|
|
||||||
- Issue #3313: Fixed a crash when a failed dlopen() call does not set
|
- Issue #3313: Fixed a crash when a failed dlopen() call does not set
|
||||||
a valid dlerror() message.
|
a valid dlerror() message.
|
||||||
|
|
||||||
|
|
|
@ -322,7 +322,7 @@ parser_st2tuple(PyST_Object *self, PyObject *args, PyObject *kw)
|
||||||
PyObject *res = 0;
|
PyObject *res = 0;
|
||||||
int ok;
|
int ok;
|
||||||
|
|
||||||
static char *keywords[] = {"ast", "line_info", "col_info", NULL};
|
static char *keywords[] = {"st", "line_info", "col_info", NULL};
|
||||||
|
|
||||||
if (self == NULL || PyModule_Check(self)) {
|
if (self == NULL || PyModule_Check(self)) {
|
||||||
ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|OO:st2tuple", keywords,
|
ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|OO:st2tuple", keywords,
|
||||||
|
@ -366,7 +366,7 @@ parser_st2list(PyST_Object *self, PyObject *args, PyObject *kw)
|
||||||
PyObject *res = 0;
|
PyObject *res = 0;
|
||||||
int ok;
|
int ok;
|
||||||
|
|
||||||
static char *keywords[] = {"ast", "line_info", "col_info", NULL};
|
static char *keywords[] = {"st", "line_info", "col_info", NULL};
|
||||||
|
|
||||||
if (self == NULL || PyModule_Check(self))
|
if (self == NULL || PyModule_Check(self))
|
||||||
ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|OO:st2list", keywords,
|
ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|OO:st2list", keywords,
|
||||||
|
@ -408,7 +408,7 @@ parser_compilest(PyST_Object *self, PyObject *args, PyObject *kw)
|
||||||
char* str = "<syntax-tree>";
|
char* str = "<syntax-tree>";
|
||||||
int ok;
|
int ok;
|
||||||
|
|
||||||
static char *keywords[] = {"ast", "filename", NULL};
|
static char *keywords[] = {"st", "filename", NULL};
|
||||||
|
|
||||||
if (self == NULL || PyModule_Check(self))
|
if (self == NULL || PyModule_Check(self))
|
||||||
ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|s:compilest", keywords,
|
ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|s:compilest", keywords,
|
||||||
|
@ -437,7 +437,7 @@ parser_isexpr(PyST_Object *self, PyObject *args, PyObject *kw)
|
||||||
PyObject* res = 0;
|
PyObject* res = 0;
|
||||||
int ok;
|
int ok;
|
||||||
|
|
||||||
static char *keywords[] = {"ast", NULL};
|
static char *keywords[] = {"st", NULL};
|
||||||
|
|
||||||
if (self == NULL || PyModule_Check(self))
|
if (self == NULL || PyModule_Check(self))
|
||||||
ok = PyArg_ParseTupleAndKeywords(args, kw, "O!:isexpr", keywords,
|
ok = PyArg_ParseTupleAndKeywords(args, kw, "O!:isexpr", keywords,
|
||||||
|
@ -460,7 +460,7 @@ parser_issuite(PyST_Object *self, PyObject *args, PyObject *kw)
|
||||||
PyObject* res = 0;
|
PyObject* res = 0;
|
||||||
int ok;
|
int ok;
|
||||||
|
|
||||||
static char *keywords[] = {"ast", NULL};
|
static char *keywords[] = {"st", NULL};
|
||||||
|
|
||||||
if (self == NULL || PyModule_Check(self))
|
if (self == NULL || PyModule_Check(self))
|
||||||
ok = PyArg_ParseTupleAndKeywords(args, kw, "O!:issuite", keywords,
|
ok = PyArg_ParseTupleAndKeywords(args, kw, "O!:issuite", keywords,
|
||||||
|
@ -3011,12 +3011,6 @@ parser__pickler(PyObject *self, PyObject *args)
|
||||||
* inheritance.
|
* inheritance.
|
||||||
*/
|
*/
|
||||||
static PyMethodDef parser_functions[] = {
|
static PyMethodDef parser_functions[] = {
|
||||||
{"ast2tuple", (PyCFunction)parser_st2tuple, PUBLIC_METHOD_TYPE,
|
|
||||||
PyDoc_STR("Creates a tuple-tree representation of an ST.")},
|
|
||||||
{"ast2list", (PyCFunction)parser_st2list, PUBLIC_METHOD_TYPE,
|
|
||||||
PyDoc_STR("Creates a list-tree representation of an ST.")},
|
|
||||||
{"compileast", (PyCFunction)parser_compilest, PUBLIC_METHOD_TYPE,
|
|
||||||
PyDoc_STR("Compiles an ST object into a code object.")},
|
|
||||||
{"compilest", (PyCFunction)parser_compilest, PUBLIC_METHOD_TYPE,
|
{"compilest", (PyCFunction)parser_compilest, PUBLIC_METHOD_TYPE,
|
||||||
PyDoc_STR("Compiles an ST object into a code object.")},
|
PyDoc_STR("Compiles an ST object into a code object.")},
|
||||||
{"expr", (PyCFunction)parser_expr, PUBLIC_METHOD_TYPE,
|
{"expr", (PyCFunction)parser_expr, PUBLIC_METHOD_TYPE,
|
||||||
|
@ -3027,16 +3021,12 @@ static PyMethodDef parser_functions[] = {
|
||||||
PyDoc_STR("Determines if an ST object was created from a suite.")},
|
PyDoc_STR("Determines if an ST object was created from a suite.")},
|
||||||
{"suite", (PyCFunction)parser_suite, PUBLIC_METHOD_TYPE,
|
{"suite", (PyCFunction)parser_suite, PUBLIC_METHOD_TYPE,
|
||||||
PyDoc_STR("Creates an ST object from a suite.")},
|
PyDoc_STR("Creates an ST object from a suite.")},
|
||||||
{"sequence2ast", (PyCFunction)parser_tuple2st, PUBLIC_METHOD_TYPE,
|
|
||||||
PyDoc_STR("Creates an ST object from a tree representation.")},
|
|
||||||
{"sequence2st", (PyCFunction)parser_tuple2st, PUBLIC_METHOD_TYPE,
|
{"sequence2st", (PyCFunction)parser_tuple2st, PUBLIC_METHOD_TYPE,
|
||||||
PyDoc_STR("Creates an ST object from a tree representation.")},
|
PyDoc_STR("Creates an ST object from a tree representation.")},
|
||||||
{"st2tuple", (PyCFunction)parser_st2tuple, PUBLIC_METHOD_TYPE,
|
{"st2tuple", (PyCFunction)parser_st2tuple, PUBLIC_METHOD_TYPE,
|
||||||
PyDoc_STR("Creates a tuple-tree representation of an ST.")},
|
PyDoc_STR("Creates a tuple-tree representation of an ST.")},
|
||||||
{"st2list", (PyCFunction)parser_st2list, PUBLIC_METHOD_TYPE,
|
{"st2list", (PyCFunction)parser_st2list, PUBLIC_METHOD_TYPE,
|
||||||
PyDoc_STR("Creates a list-tree representation of an ST.")},
|
PyDoc_STR("Creates a list-tree representation of an ST.")},
|
||||||
{"tuple2ast", (PyCFunction)parser_tuple2st, PUBLIC_METHOD_TYPE,
|
|
||||||
PyDoc_STR("Creates an ST object from a tree representation.")},
|
|
||||||
{"tuple2st", (PyCFunction)parser_tuple2st, PUBLIC_METHOD_TYPE,
|
{"tuple2st", (PyCFunction)parser_tuple2st, PUBLIC_METHOD_TYPE,
|
||||||
PyDoc_STR("Creates an ST object from a tree representation.")},
|
PyDoc_STR("Creates an ST object from a tree representation.")},
|
||||||
|
|
||||||
|
@ -3089,8 +3079,6 @@ PyInit_parser(void)
|
||||||
if (PyModule_AddObject(module, "ParserError", parser_error) != 0)
|
if (PyModule_AddObject(module, "ParserError", parser_error) != 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
Py_INCREF(&PyST_Type);
|
|
||||||
PyModule_AddObject(module, "ASTType", (PyObject*)&PyST_Type);
|
|
||||||
Py_INCREF(&PyST_Type);
|
Py_INCREF(&PyST_Type);
|
||||||
PyModule_AddObject(module, "STType", (PyObject*)&PyST_Type);
|
PyModule_AddObject(module, "STType", (PyObject*)&PyST_Type);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue