summaryrefslogtreecommitdiff
path: root/Parser
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-09-27 17:42:37 +0300
committerGitHub <noreply@github.com>2018-09-27 17:42:37 +0300
commit3f22811fef73aec848d961593d95fa877f77ecbf (patch)
tree025ca176b2993e8d85a0961f994794c3f9801032 /Parser
parenta94ee12c26aa8dd7dce01373779df8055aff765b (diff)
downloadcpython-git-3f22811fef73aec848d961593d95fa877f77ecbf.tar.gz
bpo-32892: Use ast.Constant instead of specific constant AST types. (GH-9445)
Diffstat (limited to 'Parser')
-rw-r--r--Parser/Python.asdl12
-rw-r--r--Parser/asdl_c.py39
2 files changed, 6 insertions, 45 deletions
diff --git a/Parser/Python.asdl b/Parser/Python.asdl
index f470ad13b6..eee982be1c 100644
--- a/Parser/Python.asdl
+++ b/Parser/Python.asdl
@@ -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
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
index 44e3d40c61..4c280a96c3 100644
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -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;