mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
bpo-32892: Use ast.Constant instead of specific constant AST types. (GH-9445)
This commit is contained in:
parent
a94ee12c26
commit
3f22811fef
20 changed files with 337 additions and 678 deletions
|
|
@ -1,8 +1,5 @@
|
|||
-- ASDL's 7 builtin types are:
|
||||
-- identifier, int, string, bytes, object, singleton, constant
|
||||
--
|
||||
-- singleton: None, True or False
|
||||
-- constant can be None, whereas None means "no value" for object.
|
||||
-- ASDL's 5 builtin types are:
|
||||
-- identifier, int, string, object, constant
|
||||
|
||||
module Python
|
||||
{
|
||||
|
|
@ -75,13 +72,8 @@ module Python
|
|||
-- x < 4 < 3 and (x < 4) < 3
|
||||
| Compare(expr left, cmpop* ops, expr* comparators)
|
||||
| Call(expr func, expr* args, keyword* keywords)
|
||||
| Num(object n) -- a number as a PyObject.
|
||||
| Str(string s) -- need to specify raw, unicode, etc?
|
||||
| FormattedValue(expr value, int? conversion, expr? format_spec)
|
||||
| JoinedStr(expr* values)
|
||||
| Bytes(bytes s)
|
||||
| NameConstant(singleton value)
|
||||
| Ellipsis
|
||||
| Constant(constant value)
|
||||
|
||||
-- the following expression can appear in assignment context
|
||||
|
|
|
|||
|
|
@ -855,17 +855,6 @@ static PyObject* ast2obj_int(long b)
|
|||
|
||||
/* Conversion Python -> AST */
|
||||
|
||||
static int obj2ast_singleton(PyObject *obj, PyObject** out, PyArena* arena)
|
||||
{
|
||||
if (obj != Py_None && obj != Py_True && obj != Py_False) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"AST singleton must be True, False, or None");
|
||||
return 1;
|
||||
}
|
||||
*out = obj;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
|
||||
{
|
||||
if (obj == Py_None)
|
||||
|
|
@ -883,13 +872,11 @@ static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
|
|||
|
||||
static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena)
|
||||
{
|
||||
if (obj) {
|
||||
if (PyArena_AddPyObject(arena, obj) < 0) {
|
||||
*out = NULL;
|
||||
return -1;
|
||||
}
|
||||
Py_INCREF(obj);
|
||||
if (PyArena_AddPyObject(arena, obj) < 0) {
|
||||
*out = NULL;
|
||||
return -1;
|
||||
}
|
||||
Py_INCREF(obj);
|
||||
*out = obj;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -903,24 +890,6 @@ static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
|
|||
return obj2ast_object(obj, out, arena);
|
||||
}
|
||||
|
||||
static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
|
||||
{
|
||||
if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
|
||||
PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
|
||||
return 1;
|
||||
}
|
||||
return obj2ast_object(obj, out, arena);
|
||||
}
|
||||
|
||||
static int obj2ast_bytes(PyObject* obj, PyObject** out, PyArena* arena)
|
||||
{
|
||||
if (!PyBytes_CheckExact(obj)) {
|
||||
PyErr_SetString(PyExc_TypeError, "AST bytes must be of type bytes");
|
||||
return 1;
|
||||
}
|
||||
return obj2ast_object(obj, out, arena);
|
||||
}
|
||||
|
||||
static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
|
||||
{
|
||||
int i;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue