diff options
| author | Serhiy Storchaka <storchaka@gmail.com> | 2018-09-27 14:42:37 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-09-27 14:42:37 (GMT) |
| commit | 3f22811fef73aec848d961593d95fa877f77ecbf (patch) | |
| tree | 025ca176b2993e8d85a0961f994794c3f9801032 /Parser/asdl_c.py | |
| parent | a94ee12c26aa8dd7dce01373779df8055aff765b (diff) | |
| download | cpython-3f22811fef73aec848d961593d95fa877f77ecbf.zip cpython-3f22811fef73aec848d961593d95fa877f77ecbf.tar.gz cpython-3f22811fef73aec848d961593d95fa877f77ecbf.tar.bz2 | |
bpo-32892: Use ast.Constant instead of specific constant AST types. (GH-9445)
Diffstat (limited to 'Parser/asdl_c.py')
| -rw-r--r-- | Parser/asdl_c.py | 39 |
1 files changed, 4 insertions, 35 deletions
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py index 44e3d40..4c280a9 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; |
