From 62af56412a8c773247c801ce4d6204067c629b9e Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sat, 12 Mar 2011 18:28:16 -0600 Subject: convert ast versioning to mercurial --- Python/Python-ast.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 2c09f96f0e..726227cebb 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -2,7 +2,7 @@ /* - __version__ 82163. + __version__ 68409:c017695acf19. This module must be committed separately after each AST grammar change; The __version__ number is set to the revision number of the commit @@ -6739,7 +6739,8 @@ PyInit__ast(void) NULL; if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) return NULL; - if (PyModule_AddStringConstant(m, "__version__", "82163") < 0) + if (PyModule_AddStringConstant(m, "__version__", "68409:c017695acf19") + < 0) return NULL; if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL; -- cgit v1.2.1 From a32ee4902fcf9c19d70af80a1ea840c7f10e1f24 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sat, 12 Mar 2011 18:35:23 -0600 Subject: bump ast version --- Python/Python-ast.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 726227cebb..3150d104eb 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -2,7 +2,7 @@ /* - __version__ 68409:c017695acf19. + __version__ 68410:0daa6ba25d9b. This module must be committed separately after each AST grammar change; The __version__ number is set to the revision number of the commit @@ -6739,7 +6739,7 @@ PyInit__ast(void) NULL; if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) return NULL; - if (PyModule_AddStringConstant(m, "__version__", "68409:c017695acf19") + if (PyModule_AddStringConstant(m, "__version__", "68410:0daa6ba25d9b") < 0) return NULL; if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return -- cgit v1.2.1 From ae66aaa9e45d8e330acc895b04f183995c45016d Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sun, 13 Mar 2011 16:36:08 -0500 Subject: use only the hex version, since the revno is unreliable across repos --- Python/Python-ast.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 3150d104eb..6b1ea3cbab 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -2,7 +2,7 @@ /* - __version__ 68410:0daa6ba25d9b. + __version__ 0daa6ba25d9b. This module must be committed separately after each AST grammar change; The __version__ number is set to the revision number of the commit @@ -6739,8 +6739,7 @@ PyInit__ast(void) NULL; if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) return NULL; - if (PyModule_AddStringConstant(m, "__version__", "68410:0daa6ba25d9b") - < 0) + if (PyModule_AddStringConstant(m, "__version__", "0daa6ba25d9b") < 0) return NULL; if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL; -- cgit v1.2.1 From 21cba104ee05a4fe9df4e4b8a4424a4ac1af22a5 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 27 May 2011 13:58:08 -0500 Subject: reflect with statements with multiple items in the AST (closes #12106) --- Python/Python-ast.c | 161 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 121 insertions(+), 40 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 6b1ea3cbab..2364db3071 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -95,8 +95,7 @@ static char *If_fields[]={ }; static PyTypeObject *With_type; static char *With_fields[]={ - "context_expr", - "optional_vars", + "items", "body", }; static PyTypeObject *Raise_type; @@ -392,6 +391,12 @@ static char *alias_fields[]={ "name", "asname", }; +static PyTypeObject *withitem_type; +static PyObject* ast2obj_withitem(void*); +static char *withitem_fields[]={ + "context_expr", + "optional_vars", +}; static int @@ -680,7 +685,7 @@ static int init_types(void) if (!While_type) return 0; If_type = make_type("If", stmt_type, If_fields, 3); if (!If_type) return 0; - With_type = make_type("With", stmt_type, With_fields, 3); + With_type = make_type("With", stmt_type, With_fields, 2); if (!With_type) return 0; Raise_type = make_type("Raise", stmt_type, Raise_fields, 2); if (!Raise_type) return 0; @@ -938,6 +943,8 @@ static int init_types(void) if (!keyword_type) return 0; alias_type = make_type("alias", &AST_type, alias_fields, 2); if (!alias_type) return 0; + withitem_type = make_type("withitem", &AST_type, withitem_fields, 2); + if (!withitem_type) return 0; initialized = 1; return 1; } @@ -960,6 +967,7 @@ static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); +static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena); mod_ty Module(asdl_seq * body, PyArena *arena) @@ -1225,21 +1233,15 @@ If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int } stmt_ty -With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno, - int col_offset, PyArena *arena) +With(asdl_seq * items, asdl_seq * body, int lineno, int col_offset, PyArena + *arena) { stmt_ty p; - if (!context_expr) { - PyErr_SetString(PyExc_ValueError, - "field context_expr is required for With"); - return NULL; - } p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); if (!p) return NULL; p->kind = With_kind; - p->v.With.context_expr = context_expr; - p->v.With.optional_vars = optional_vars; + p->v.With.items = items; p->v.With.body = body; p->lineno = lineno; p->col_offset = col_offset; @@ -2135,6 +2137,23 @@ alias(identifier name, identifier asname, PyArena *arena) return p; } +withitem_ty +withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) +{ + withitem_ty p; + if (!context_expr) { + PyErr_SetString(PyExc_ValueError, + "field context_expr is required for withitem"); + return NULL; + } + p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->context_expr = context_expr; + p->optional_vars = optional_vars; + return p; +} + PyObject* ast2obj_mod(void* _o) @@ -2390,15 +2409,9 @@ ast2obj_stmt(void* _o) case With_kind: result = PyType_GenericNew(With_type, NULL, NULL); if (!result) goto failed; - value = ast2obj_expr(o->v.With.context_expr); + value = ast2obj_list(o->v.With.items, ast2obj_withitem); if (!value) goto failed; - if (PyObject_SetAttrString(result, "context_expr", value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_expr(o->v.With.optional_vars); - if (!value) goto failed; - if (PyObject_SetAttrString(result, "optional_vars", value) == - -1) + if (PyObject_SetAttrString(result, "items", value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.With.body, ast2obj_stmt); @@ -3370,6 +3383,35 @@ failed: return NULL; } +PyObject* +ast2obj_withitem(void* _o) +{ + withitem_ty o = (withitem_ty)_o; + PyObject *result = NULL, *value = NULL; + if (!o) { + Py_INCREF(Py_None); + return Py_None; + } + + result = PyType_GenericNew(withitem_type, NULL, NULL); + if (!result) return NULL; + value = ast2obj_expr(o->context_expr); + if (!value) goto failed; + if (PyObject_SetAttrString(result, "context_expr", value) == -1) + goto failed; + Py_DECREF(value); + value = ast2obj_expr(o->optional_vars); + if (!value) goto failed; + if (PyObject_SetAttrString(result, "optional_vars", value) == -1) + goto failed; + Py_DECREF(value); + return result; +failed: + Py_XDECREF(value); + Py_XDECREF(result); + return NULL; +} + int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) @@ -4210,33 +4252,34 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) return 1; } if (isinstance) { - expr_ty context_expr; - expr_ty optional_vars; + asdl_seq* items; asdl_seq* body; - if (PyObject_HasAttrString(obj, "context_expr")) { + if (PyObject_HasAttrString(obj, "items")) { int res; - tmp = PyObject_GetAttrString(obj, "context_expr"); + Py_ssize_t len; + Py_ssize_t i; + tmp = PyObject_GetAttrString(obj, "items"); if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &context_expr, arena); - if (res != 0) goto failed; + if (!PyList_Check(tmp)) { + PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); + goto failed; + } + len = PyList_GET_SIZE(tmp); + items = asdl_seq_new(len, arena); + if (items == NULL) goto failed; + for (i = 0; i < len; i++) { + withitem_ty value; + res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &value, arena); + if (res != 0) goto failed; + asdl_seq_SET(items, i, value); + } Py_XDECREF(tmp); tmp = NULL; } else { - PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from With"); + PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); return 1; } - if (PyObject_HasAttrString(obj, "optional_vars")) { - int res; - tmp = PyObject_GetAttrString(obj, "optional_vars"); - if (tmp == NULL) goto failed; - res = obj2ast_expr(tmp, &optional_vars, arena); - if (res != 0) goto failed; - Py_XDECREF(tmp); - tmp = NULL; - } else { - optional_vars = NULL; - } if (PyObject_HasAttrString(obj, "body")) { int res; Py_ssize_t len; @@ -4262,8 +4305,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); return 1; } - *out = With(context_expr, optional_vars, body, lineno, - col_offset, arena); + *out = With(items, body, lineno, col_offset, arena); if (*out == NULL) goto failed; return 0; } @@ -6723,6 +6765,43 @@ failed: return 1; } +int +obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) +{ + PyObject* tmp = NULL; + expr_ty context_expr; + expr_ty optional_vars; + + if (PyObject_HasAttrString(obj, "context_expr")) { + int res; + tmp = PyObject_GetAttrString(obj, "context_expr"); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &context_expr, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); + return 1; + } + if (PyObject_HasAttrString(obj, "optional_vars")) { + int res; + tmp = PyObject_GetAttrString(obj, "optional_vars"); + if (tmp == NULL) goto failed; + res = obj2ast_expr(tmp, &optional_vars, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + optional_vars = NULL; + } + *out = withitem(context_expr, optional_vars, arena); + return 0; +failed: + Py_XDECREF(tmp); + return 1; +} + static struct PyModuleDef _astmodule = { PyModuleDef_HEAD_INIT, "_ast" @@ -6940,6 +7019,8 @@ PyInit__ast(void) return NULL; if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return NULL; + if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0) + return NULL; return m; } -- cgit v1.2.1 From 3e849018fb1479352d59e40376e56db9bb1e4eaa Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 27 May 2011 14:01:01 -0500 Subject: bump ast version --- Python/Python-ast.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 2364db3071..f076c7e964 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -2,7 +2,7 @@ /* - __version__ 0daa6ba25d9b. + __version__ 9b11cc4e2918. This module must be committed separately after each AST grammar change; The __version__ number is set to the revision number of the commit @@ -6818,7 +6818,7 @@ PyInit__ast(void) NULL; if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) return NULL; - if (PyModule_AddStringConstant(m, "__version__", "0daa6ba25d9b") < 0) + if (PyModule_AddStringConstant(m, "__version__", "9b11cc4e2918") < 0) return NULL; if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL; -- cgit v1.2.1 From 6d1f6c22f99d5c3c7df1682b77d8dc4266bc3bf3 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sun, 29 May 2011 11:43:10 -0500 Subject: unify TryExcept and TryFinally (closes #12199) --- Python/Python-ast.c | 132 ++++++++++++---------------------------------------- 1 file changed, 31 insertions(+), 101 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index f076c7e964..66e09b71a1 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -103,15 +103,11 @@ static char *Raise_fields[]={ "exc", "cause", }; -static PyTypeObject *TryExcept_type; -static char *TryExcept_fields[]={ +static PyTypeObject *Try_type; +static char *Try_fields[]={ "body", "handlers", "orelse", -}; -static PyTypeObject *TryFinally_type; -static char *TryFinally_fields[]={ - "body", "finalbody", }; static PyTypeObject *Assert_type; @@ -689,11 +685,8 @@ static int init_types(void) if (!With_type) return 0; Raise_type = make_type("Raise", stmt_type, Raise_fields, 2); if (!Raise_type) return 0; - TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3); - if (!TryExcept_type) return 0; - TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields, - 2); - if (!TryFinally_type) return 0; + Try_type = make_type("Try", stmt_type, Try_fields, 4); + if (!Try_type) return 0; Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); if (!Assert_type) return 0; Import_type = make_type("Import", stmt_type, Import_fields, 1); @@ -1264,33 +1257,18 @@ Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, PyArena *arena) } stmt_ty -TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno, - int col_offset, PyArena *arena) +Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * + finalbody, int lineno, int col_offset, PyArena *arena) { stmt_ty p; p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); if (!p) return NULL; - p->kind = TryExcept_kind; - p->v.TryExcept.body = body; - p->v.TryExcept.handlers = handlers; - p->v.TryExcept.orelse = orelse; - p->lineno = lineno; - p->col_offset = col_offset; - return p; -} - -stmt_ty -TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset, - PyArena *arena) -{ - stmt_ty p; - p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) - return NULL; - p->kind = TryFinally_kind; - p->v.TryFinally.body = body; - p->v.TryFinally.finalbody = finalbody; + p->kind = Try_kind; + p->v.Try.body = body; + p->v.Try.handlers = handlers; + p->v.Try.orelse = orelse; + p->v.Try.finalbody = finalbody; p->lineno = lineno; p->col_offset = col_offset; return p; @@ -2434,35 +2412,25 @@ ast2obj_stmt(void* _o) goto failed; Py_DECREF(value); break; - case TryExcept_kind: - result = PyType_GenericNew(TryExcept_type, NULL, NULL); + case Try_kind: + result = PyType_GenericNew(Try_type, NULL, NULL); if (!result) goto failed; - value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt); + value = ast2obj_list(o->v.Try.body, ast2obj_stmt); if (!value) goto failed; if (PyObject_SetAttrString(result, "body", value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.TryExcept.handlers, - ast2obj_excepthandler); + value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); if (!value) goto failed; if (PyObject_SetAttrString(result, "handlers", value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt); + value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); if (!value) goto failed; if (PyObject_SetAttrString(result, "orelse", value) == -1) goto failed; Py_DECREF(value); - break; - case TryFinally_kind: - result = PyType_GenericNew(TryFinally_type, NULL, NULL); - if (!result) goto failed; - value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt); - if (!value) goto failed; - if (PyObject_SetAttrString(result, "body", value) == -1) - goto failed; - Py_DECREF(value); - value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt); + value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); if (!value) goto failed; if (PyObject_SetAttrString(result, "finalbody", value) == -1) goto failed; @@ -4343,7 +4311,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (*out == NULL) goto failed; return 0; } - isinstance = PyObject_IsInstance(obj, (PyObject*)TryExcept_type); + isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type); if (isinstance == -1) { return 1; } @@ -4351,6 +4319,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* body; asdl_seq* handlers; asdl_seq* orelse; + asdl_seq* finalbody; if (PyObject_HasAttrString(obj, "body")) { int res; @@ -4359,7 +4328,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) tmp = PyObject_GetAttrString(obj, "body"); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "TryExcept field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -4374,7 +4343,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_XDECREF(tmp); tmp = NULL; } else { - PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryExcept"); + PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); return 1; } if (PyObject_HasAttrString(obj, "handlers")) { @@ -4384,7 +4353,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) tmp = PyObject_GetAttrString(obj, "handlers"); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "TryExcept field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -4399,7 +4368,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_XDECREF(tmp); tmp = NULL; } else { - PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from TryExcept"); + PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); return 1; } if (PyObject_HasAttrString(obj, "orelse")) { @@ -4409,7 +4378,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) tmp = PyObject_GetAttrString(obj, "orelse"); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "TryExcept field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -4424,45 +4393,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_XDECREF(tmp); tmp = NULL; } else { - PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from TryExcept"); - return 1; - } - *out = TryExcept(body, handlers, orelse, lineno, col_offset, - arena); - if (*out == NULL) goto failed; - return 0; - } - isinstance = PyObject_IsInstance(obj, (PyObject*)TryFinally_type); - if (isinstance == -1) { - return 1; - } - if (isinstance) { - asdl_seq* body; - asdl_seq* finalbody; - - if (PyObject_HasAttrString(obj, "body")) { - int res; - Py_ssize_t len; - Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "body"); - if (tmp == NULL) goto failed; - if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "TryFinally field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); - goto failed; - } - len = PyList_GET_SIZE(tmp); - body = asdl_seq_new(len, arena); - if (body == NULL) goto failed; - for (i = 0; i < len; i++) { - stmt_ty value; - res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); - if (res != 0) goto failed; - asdl_seq_SET(body, i, value); - } - Py_XDECREF(tmp); - tmp = NULL; - } else { - PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryFinally"); + PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); return 1; } if (PyObject_HasAttrString(obj, "finalbody")) { @@ -4472,7 +4403,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) tmp = PyObject_GetAttrString(obj, "finalbody"); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { - PyErr_Format(PyExc_TypeError, "TryFinally field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); + PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); goto failed; } len = PyList_GET_SIZE(tmp); @@ -4487,10 +4418,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) Py_XDECREF(tmp); tmp = NULL; } else { - PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from TryFinally"); + PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); return 1; } - *out = TryFinally(body, finalbody, lineno, col_offset, arena); + *out = Try(body, handlers, orelse, finalbody, lineno, + col_offset, arena); if (*out == NULL) goto failed; return 0; } @@ -6853,10 +6785,8 @@ PyInit__ast(void) NULL; if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return NULL; - if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) < - 0) return NULL; - if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) < - 0) return NULL; + if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return + NULL; if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) return NULL; if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) -- cgit v1.2.1 From 8ba4624df8c09a4de6be4732caac2283891789f5 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sun, 29 May 2011 11:45:29 -0500 Subject: bump ast version --- Python/Python-ast.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 66e09b71a1..b597626463 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -2,7 +2,7 @@ /* - __version__ 9b11cc4e2918. + __version__ e0e663132363. This module must be committed separately after each AST grammar change; The __version__ number is set to the revision number of the commit @@ -6750,7 +6750,7 @@ PyInit__ast(void) NULL; if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) return NULL; - if (PyModule_AddStringConstant(m, "__version__", "9b11cc4e2918") < 0) + if (PyModule_AddStringConstant(m, "__version__", "e0e663132363") < 0) return NULL; if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL; -- cgit v1.2.1 From 2a0e1b24e9ddbfa621889f48dbbeaa370a8b4429 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 15 Jul 2011 21:10:13 -0500 Subject: remove ast.__version__ (closes #12273) --- Python/Python-ast.c | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index b597626463..96c6bf83fc 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -1,14 +1,5 @@ /* File automatically generated by Parser/asdl_c.py. */ - -/* - __version__ e0e663132363. - - This module must be committed separately after each AST grammar change; - The __version__ number is set to the revision number of the commit - containing the grammar change. -*/ - #include "Python.h" #include "Python-ast.h" @@ -6750,8 +6741,6 @@ PyInit__ast(void) NULL; if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) return NULL; - if (PyModule_AddStringConstant(m, "__version__", "e0e663132363") < 0) - return NULL; if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL; if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) -- cgit v1.2.1 From 7bf0e0ea86f0b88e6cf0c6c6bd8a7113761769df Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Tue, 9 Aug 2011 16:08:39 -0500 Subject: add a asdl bytes type, so Bytes.s be properly typechecked --- Python/Python-ast.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 68b109722b..f6e345c916 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -573,6 +573,7 @@ static PyObject* ast2obj_object(void *o) } #define ast2obj_identifier ast2obj_object #define ast2obj_string ast2obj_object +#define ast2obj_bytes ast2obj_object static PyObject* ast2obj_int(long b) { @@ -610,6 +611,15 @@ static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) 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; @@ -1773,7 +1783,7 @@ Str(string s, int lineno, int col_offset, PyArena *arena) } expr_ty -Bytes(string s, int lineno, int col_offset, PyArena *arena) +Bytes(bytes s, int lineno, int col_offset, PyArena *arena) { expr_ty p; if (!s) { @@ -2804,7 +2814,7 @@ ast2obj_expr(void* _o) case Bytes_kind: result = PyType_GenericNew(Bytes_type, NULL, NULL); if (!result) goto failed; - value = ast2obj_string(o->v.Bytes.s); + value = ast2obj_bytes(o->v.Bytes.s); if (!value) goto failed; if (PyObject_SetAttrString(result, "s", value) == -1) goto failed; @@ -5509,13 +5519,13 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) return 1; } if (isinstance) { - string s; + bytes s; if (PyObject_HasAttrString(obj, "s")) { int res; tmp = PyObject_GetAttrString(obj, "s"); if (tmp == NULL) goto failed; - res = obj2ast_string(tmp, &s, arena); + res = obj2ast_bytes(tmp, &s, arena); if (res != 0) goto failed; Py_XDECREF(tmp); tmp = NULL; -- cgit v1.2.1 From c3eb93fe1ce5f5ff2666fb9f34a6fd7c46279554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Mon, 10 Oct 2011 18:11:30 +0200 Subject: Use identifier API for PyObject_GetAttrString. --- Python/Python-ast.c | 601 +++++++++++++++++++++++++++++----------------------- 1 file changed, 333 insertions(+), 268 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index ff79757c35..2ed36cd220 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -7,6 +7,7 @@ static PyTypeObject AST_type; static PyTypeObject *mod_type; static PyObject* ast2obj_mod(void*); static PyTypeObject *Module_type; +_Py_identifier(body); static char *Module_fields[]={ "body", }; @@ -23,12 +24,18 @@ static char *Suite_fields[]={ "body", }; static PyTypeObject *stmt_type; +_Py_identifier(lineno); +_Py_identifier(col_offset); static char *stmt_attributes[] = { "lineno", "col_offset", }; static PyObject* ast2obj_stmt(void*); static PyTypeObject *FunctionDef_type; +_Py_identifier(name); +_Py_identifier(args); +_Py_identifier(decorator_list); +_Py_identifier(returns); static char *FunctionDef_fields[]={ "name", "args", @@ -37,6 +44,10 @@ static char *FunctionDef_fields[]={ "returns", }; static PyTypeObject *ClassDef_type; +_Py_identifier(bases); +_Py_identifier(keywords); +_Py_identifier(starargs); +_Py_identifier(kwargs); static char *ClassDef_fields[]={ "name", "bases", @@ -47,10 +58,12 @@ static char *ClassDef_fields[]={ "decorator_list", }; static PyTypeObject *Return_type; +_Py_identifier(value); static char *Return_fields[]={ "value", }; static PyTypeObject *Delete_type; +_Py_identifier(targets); static char *Delete_fields[]={ "targets", }; @@ -60,12 +73,16 @@ static char *Assign_fields[]={ "value", }; static PyTypeObject *AugAssign_type; +_Py_identifier(target); +_Py_identifier(op); static char *AugAssign_fields[]={ "target", "op", "value", }; static PyTypeObject *For_type; +_Py_identifier(iter); +_Py_identifier(orelse); static char *For_fields[]={ "target", "iter", @@ -73,6 +90,7 @@ static char *For_fields[]={ "orelse", }; static PyTypeObject *While_type; +_Py_identifier(test); static char *While_fields[]={ "test", "body", @@ -85,16 +103,21 @@ static char *If_fields[]={ "orelse", }; static PyTypeObject *With_type; +_Py_identifier(items); static char *With_fields[]={ "items", "body", }; static PyTypeObject *Raise_type; +_Py_identifier(exc); +_Py_identifier(cause); static char *Raise_fields[]={ "exc", "cause", }; static PyTypeObject *Try_type; +_Py_identifier(handlers); +_Py_identifier(finalbody); static char *Try_fields[]={ "body", "handlers", @@ -102,15 +125,19 @@ static char *Try_fields[]={ "finalbody", }; static PyTypeObject *Assert_type; +_Py_identifier(msg); static char *Assert_fields[]={ "test", "msg", }; static PyTypeObject *Import_type; +_Py_identifier(names); static char *Import_fields[]={ "names", }; static PyTypeObject *ImportFrom_type; +_Py_identifier(module); +_Py_identifier(level); static char *ImportFrom_fields[]={ "module", "names", @@ -138,17 +165,21 @@ static char *expr_attributes[] = { }; static PyObject* ast2obj_expr(void*); static PyTypeObject *BoolOp_type; +_Py_identifier(values); static char *BoolOp_fields[]={ "op", "values", }; static PyTypeObject *BinOp_type; +_Py_identifier(left); +_Py_identifier(right); static char *BinOp_fields[]={ "left", "op", "right", }; static PyTypeObject *UnaryOp_type; +_Py_identifier(operand); static char *UnaryOp_fields[]={ "op", "operand", @@ -165,15 +196,19 @@ static char *IfExp_fields[]={ "orelse", }; static PyTypeObject *Dict_type; +_Py_identifier(keys); static char *Dict_fields[]={ "keys", "values", }; static PyTypeObject *Set_type; +_Py_identifier(elts); static char *Set_fields[]={ "elts", }; static PyTypeObject *ListComp_type; +_Py_identifier(elt); +_Py_identifier(generators); static char *ListComp_fields[]={ "elt", "generators", @@ -184,6 +219,7 @@ static char *SetComp_fields[]={ "generators", }; static PyTypeObject *DictComp_type; +_Py_identifier(key); static char *DictComp_fields[]={ "key", "value", @@ -199,12 +235,15 @@ static char *Yield_fields[]={ "value", }; static PyTypeObject *Compare_type; +_Py_identifier(ops); +_Py_identifier(comparators); static char *Compare_fields[]={ "left", "ops", "comparators", }; static PyTypeObject *Call_type; +_Py_identifier(func); static char *Call_fields[]={ "func", "args", @@ -213,10 +252,12 @@ static char *Call_fields[]={ "kwargs", }; static PyTypeObject *Num_type; +_Py_identifier(n); static char *Num_fields[]={ "n", }; static PyTypeObject *Str_type; +_Py_identifier(s); static char *Str_fields[]={ "s", }; @@ -226,12 +267,15 @@ static char *Bytes_fields[]={ }; static PyTypeObject *Ellipsis_type; static PyTypeObject *Attribute_type; +_Py_identifier(attr); +_Py_identifier(ctx); static char *Attribute_fields[]={ "value", "attr", "ctx", }; static PyTypeObject *Subscript_type; +_Py_identifier(slice); static char *Subscript_fields[]={ "value", "slice", @@ -243,6 +287,7 @@ static char *Starred_fields[]={ "ctx", }; static PyTypeObject *Name_type; +_Py_identifier(id); static char *Name_fields[]={ "id", "ctx", @@ -270,12 +315,16 @@ static PyTypeObject *Param_type; static PyTypeObject *slice_type; static PyObject* ast2obj_slice(void*); static PyTypeObject *Slice_type; +_Py_identifier(lower); +_Py_identifier(upper); +_Py_identifier(step); static char *Slice_fields[]={ "lower", "upper", "step", }; static PyTypeObject *ExtSlice_type; +_Py_identifier(dims); static char *ExtSlice_fields[]={ "dims", }; @@ -331,6 +380,7 @@ static PyTypeObject *In_type; static PyTypeObject *NotIn_type; static PyTypeObject *comprehension_type; static PyObject* ast2obj_comprehension(void*); +_Py_identifier(ifs); static char *comprehension_fields[]={ "target", "iter", @@ -343,6 +393,7 @@ static char *excepthandler_attributes[] = { }; static PyObject* ast2obj_excepthandler(void*); static PyTypeObject *ExceptHandler_type; +_Py_identifier(type); static char *ExceptHandler_fields[]={ "type", "name", @@ -350,6 +401,13 @@ static char *ExceptHandler_fields[]={ }; static PyTypeObject *arguments_type; static PyObject* ast2obj_arguments(void*); +_Py_identifier(vararg); +_Py_identifier(varargannotation); +_Py_identifier(kwonlyargs); +_Py_identifier(kwarg); +_Py_identifier(kwargannotation); +_Py_identifier(defaults); +_Py_identifier(kw_defaults); static char *arguments_fields[]={ "args", "vararg", @@ -362,6 +420,8 @@ static char *arguments_fields[]={ }; static PyTypeObject *arg_type; static PyObject* ast2obj_arg(void*); +_Py_identifier(arg); +_Py_identifier(annotation); static char *arg_fields[]={ "arg", "annotation", @@ -374,12 +434,15 @@ static char *keyword_fields[]={ }; static PyTypeObject *alias_type; static PyObject* ast2obj_alias(void*); +_Py_identifier(asname); static char *alias_fields[]={ "name", "asname", }; static PyTypeObject *withitem_type; static PyObject* ast2obj_withitem(void*); +_Py_identifier(context_expr); +_Py_identifier(optional_vars); static char *withitem_fields[]={ "context_expr", "optional_vars", @@ -389,10 +452,11 @@ static char *withitem_fields[]={ static int ast_type_init(PyObject *self, PyObject *args, PyObject *kw) { + _Py_identifier(_fields); Py_ssize_t i, numfields = 0; int res = -1; PyObject *key, *value, *fields; - fields = PyObject_GetAttrString((PyObject*)Py_TYPE(self), "_fields"); + fields = _PyObject_GetAttrId((PyObject*)Py_TYPE(self), &PyId__fields); if (!fields) PyErr_Clear(); if (fields) { @@ -442,7 +506,8 @@ static PyObject * ast_type_reduce(PyObject *self, PyObject *unused) { PyObject *res; - PyObject *dict = PyObject_GetAttrString(self, "__dict__"); + _Py_identifier(__dict__); + PyObject *dict = _PyObject_GetAttrId(self, &PyId___dict__); if (dict == NULL) { if (PyErr_ExceptionMatches(PyExc_AttributeError)) PyErr_Clear(); @@ -3415,11 +3480,11 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) if (isinstance) { asdl_seq* body; - if (PyObject_HasAttrString(obj, "body")) { + if (_PyObject_HasAttrId(obj, &PyId_body)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "body"); + tmp = _PyObject_GetAttrId(obj, &PyId_body); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -3451,11 +3516,11 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) if (isinstance) { asdl_seq* body; - if (PyObject_HasAttrString(obj, "body")) { + if (_PyObject_HasAttrId(obj, &PyId_body)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "body"); + tmp = _PyObject_GetAttrId(obj, &PyId_body); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -3487,9 +3552,9 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) if (isinstance) { expr_ty body; - if (PyObject_HasAttrString(obj, "body")) { + if (_PyObject_HasAttrId(obj, &PyId_body)) { int res; - tmp = PyObject_GetAttrString(obj, "body"); + tmp = _PyObject_GetAttrId(obj, &PyId_body); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &body, arena); if (res != 0) goto failed; @@ -3510,11 +3575,11 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) if (isinstance) { asdl_seq* body; - if (PyObject_HasAttrString(obj, "body")) { + if (_PyObject_HasAttrId(obj, &PyId_body)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "body"); + tmp = _PyObject_GetAttrId(obj, &PyId_body); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -3559,9 +3624,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) *out = NULL; return 0; } - if (PyObject_HasAttrString(obj, "lineno")) { + if (_PyObject_HasAttrId(obj, &PyId_lineno)) { int res; - tmp = PyObject_GetAttrString(obj, "lineno"); + tmp = _PyObject_GetAttrId(obj, &PyId_lineno); if (tmp == NULL) goto failed; res = obj2ast_int(tmp, &lineno, arena); if (res != 0) goto failed; @@ -3571,9 +3636,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); return 1; } - if (PyObject_HasAttrString(obj, "col_offset")) { + if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { int res; - tmp = PyObject_GetAttrString(obj, "col_offset"); + tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); if (tmp == NULL) goto failed; res = obj2ast_int(tmp, &col_offset, arena); if (res != 0) goto failed; @@ -3594,9 +3659,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* decorator_list; expr_ty returns; - if (PyObject_HasAttrString(obj, "name")) { + if (_PyObject_HasAttrId(obj, &PyId_name)) { int res; - tmp = PyObject_GetAttrString(obj, "name"); + tmp = _PyObject_GetAttrId(obj, &PyId_name); if (tmp == NULL) goto failed; res = obj2ast_identifier(tmp, &name, arena); if (res != 0) goto failed; @@ -3606,9 +3671,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); return 1; } - if (PyObject_HasAttrString(obj, "args")) { + if (_PyObject_HasAttrId(obj, &PyId_args)) { int res; - tmp = PyObject_GetAttrString(obj, "args"); + tmp = _PyObject_GetAttrId(obj, &PyId_args); if (tmp == NULL) goto failed; res = obj2ast_arguments(tmp, &args, arena); if (res != 0) goto failed; @@ -3618,11 +3683,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); return 1; } - if (PyObject_HasAttrString(obj, "body")) { + if (_PyObject_HasAttrId(obj, &PyId_body)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "body"); + tmp = _PyObject_GetAttrId(obj, &PyId_body); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -3643,11 +3708,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); return 1; } - if (PyObject_HasAttrString(obj, "decorator_list")) { + if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "decorator_list"); + tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -3668,9 +3733,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); return 1; } - if (PyObject_HasAttrString(obj, "returns")) { + if (_PyObject_HasAttrId(obj, &PyId_returns)) { int res; - tmp = PyObject_GetAttrString(obj, "returns"); + tmp = _PyObject_GetAttrId(obj, &PyId_returns); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &returns, arena); if (res != 0) goto failed; @@ -3697,9 +3762,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* body; asdl_seq* decorator_list; - if (PyObject_HasAttrString(obj, "name")) { + if (_PyObject_HasAttrId(obj, &PyId_name)) { int res; - tmp = PyObject_GetAttrString(obj, "name"); + tmp = _PyObject_GetAttrId(obj, &PyId_name); if (tmp == NULL) goto failed; res = obj2ast_identifier(tmp, &name, arena); if (res != 0) goto failed; @@ -3709,11 +3774,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); return 1; } - if (PyObject_HasAttrString(obj, "bases")) { + if (_PyObject_HasAttrId(obj, &PyId_bases)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "bases"); + tmp = _PyObject_GetAttrId(obj, &PyId_bases); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -3734,11 +3799,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); return 1; } - if (PyObject_HasAttrString(obj, "keywords")) { + if (_PyObject_HasAttrId(obj, &PyId_keywords)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "keywords"); + tmp = _PyObject_GetAttrId(obj, &PyId_keywords); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -3759,9 +3824,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); return 1; } - if (PyObject_HasAttrString(obj, "starargs")) { + if (_PyObject_HasAttrId(obj, &PyId_starargs)) { int res; - tmp = PyObject_GetAttrString(obj, "starargs"); + tmp = _PyObject_GetAttrId(obj, &PyId_starargs); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &starargs, arena); if (res != 0) goto failed; @@ -3770,9 +3835,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { starargs = NULL; } - if (PyObject_HasAttrString(obj, "kwargs")) { + if (_PyObject_HasAttrId(obj, &PyId_kwargs)) { int res; - tmp = PyObject_GetAttrString(obj, "kwargs"); + tmp = _PyObject_GetAttrId(obj, &PyId_kwargs); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &kwargs, arena); if (res != 0) goto failed; @@ -3781,11 +3846,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { kwargs = NULL; } - if (PyObject_HasAttrString(obj, "body")) { + if (_PyObject_HasAttrId(obj, &PyId_body)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "body"); + tmp = _PyObject_GetAttrId(obj, &PyId_body); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -3806,11 +3871,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); return 1; } - if (PyObject_HasAttrString(obj, "decorator_list")) { + if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "decorator_list"); + tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -3843,9 +3908,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (isinstance) { expr_ty value; - if (PyObject_HasAttrString(obj, "value")) { + if (_PyObject_HasAttrId(obj, &PyId_value)) { int res; - tmp = PyObject_GetAttrString(obj, "value"); + tmp = _PyObject_GetAttrId(obj, &PyId_value); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &value, arena); if (res != 0) goto failed; @@ -3865,11 +3930,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (isinstance) { asdl_seq* targets; - if (PyObject_HasAttrString(obj, "targets")) { + if (_PyObject_HasAttrId(obj, &PyId_targets)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "targets"); + tmp = _PyObject_GetAttrId(obj, &PyId_targets); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -3902,11 +3967,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* targets; expr_ty value; - if (PyObject_HasAttrString(obj, "targets")) { + if (_PyObject_HasAttrId(obj, &PyId_targets)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "targets"); + tmp = _PyObject_GetAttrId(obj, &PyId_targets); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -3927,9 +3992,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); return 1; } - if (PyObject_HasAttrString(obj, "value")) { + if (_PyObject_HasAttrId(obj, &PyId_value)) { int res; - tmp = PyObject_GetAttrString(obj, "value"); + tmp = _PyObject_GetAttrId(obj, &PyId_value); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &value, arena); if (res != 0) goto failed; @@ -3952,9 +4017,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) operator_ty op; expr_ty value; - if (PyObject_HasAttrString(obj, "target")) { + if (_PyObject_HasAttrId(obj, &PyId_target)) { int res; - tmp = PyObject_GetAttrString(obj, "target"); + tmp = _PyObject_GetAttrId(obj, &PyId_target); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &target, arena); if (res != 0) goto failed; @@ -3964,9 +4029,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); return 1; } - if (PyObject_HasAttrString(obj, "op")) { + if (_PyObject_HasAttrId(obj, &PyId_op)) { int res; - tmp = PyObject_GetAttrString(obj, "op"); + tmp = _PyObject_GetAttrId(obj, &PyId_op); if (tmp == NULL) goto failed; res = obj2ast_operator(tmp, &op, arena); if (res != 0) goto failed; @@ -3976,9 +4041,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); return 1; } - if (PyObject_HasAttrString(obj, "value")) { + if (_PyObject_HasAttrId(obj, &PyId_value)) { int res; - tmp = PyObject_GetAttrString(obj, "value"); + tmp = _PyObject_GetAttrId(obj, &PyId_value); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &value, arena); if (res != 0) goto failed; @@ -4002,9 +4067,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* body; asdl_seq* orelse; - if (PyObject_HasAttrString(obj, "target")) { + if (_PyObject_HasAttrId(obj, &PyId_target)) { int res; - tmp = PyObject_GetAttrString(obj, "target"); + tmp = _PyObject_GetAttrId(obj, &PyId_target); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &target, arena); if (res != 0) goto failed; @@ -4014,9 +4079,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); return 1; } - if (PyObject_HasAttrString(obj, "iter")) { + if (_PyObject_HasAttrId(obj, &PyId_iter)) { int res; - tmp = PyObject_GetAttrString(obj, "iter"); + tmp = _PyObject_GetAttrId(obj, &PyId_iter); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &iter, arena); if (res != 0) goto failed; @@ -4026,11 +4091,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); return 1; } - if (PyObject_HasAttrString(obj, "body")) { + if (_PyObject_HasAttrId(obj, &PyId_body)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "body"); + tmp = _PyObject_GetAttrId(obj, &PyId_body); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -4051,11 +4116,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); return 1; } - if (PyObject_HasAttrString(obj, "orelse")) { + if (_PyObject_HasAttrId(obj, &PyId_orelse)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "orelse"); + tmp = _PyObject_GetAttrId(obj, &PyId_orelse); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -4090,9 +4155,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* body; asdl_seq* orelse; - if (PyObject_HasAttrString(obj, "test")) { + if (_PyObject_HasAttrId(obj, &PyId_test)) { int res; - tmp = PyObject_GetAttrString(obj, "test"); + tmp = _PyObject_GetAttrId(obj, &PyId_test); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &test, arena); if (res != 0) goto failed; @@ -4102,11 +4167,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); return 1; } - if (PyObject_HasAttrString(obj, "body")) { + if (_PyObject_HasAttrId(obj, &PyId_body)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "body"); + tmp = _PyObject_GetAttrId(obj, &PyId_body); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -4127,11 +4192,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); return 1; } - if (PyObject_HasAttrString(obj, "orelse")) { + if (_PyObject_HasAttrId(obj, &PyId_orelse)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "orelse"); + tmp = _PyObject_GetAttrId(obj, &PyId_orelse); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -4165,9 +4230,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* body; asdl_seq* orelse; - if (PyObject_HasAttrString(obj, "test")) { + if (_PyObject_HasAttrId(obj, &PyId_test)) { int res; - tmp = PyObject_GetAttrString(obj, "test"); + tmp = _PyObject_GetAttrId(obj, &PyId_test); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &test, arena); if (res != 0) goto failed; @@ -4177,11 +4242,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); return 1; } - if (PyObject_HasAttrString(obj, "body")) { + if (_PyObject_HasAttrId(obj, &PyId_body)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "body"); + tmp = _PyObject_GetAttrId(obj, &PyId_body); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -4202,11 +4267,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); return 1; } - if (PyObject_HasAttrString(obj, "orelse")) { + if (_PyObject_HasAttrId(obj, &PyId_orelse)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "orelse"); + tmp = _PyObject_GetAttrId(obj, &PyId_orelse); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -4239,11 +4304,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* items; asdl_seq* body; - if (PyObject_HasAttrString(obj, "items")) { + if (_PyObject_HasAttrId(obj, &PyId_items)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "items"); + tmp = _PyObject_GetAttrId(obj, &PyId_items); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -4264,11 +4329,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); return 1; } - if (PyObject_HasAttrString(obj, "body")) { + if (_PyObject_HasAttrId(obj, &PyId_body)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "body"); + tmp = _PyObject_GetAttrId(obj, &PyId_body); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -4301,9 +4366,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) expr_ty exc; expr_ty cause; - if (PyObject_HasAttrString(obj, "exc")) { + if (_PyObject_HasAttrId(obj, &PyId_exc)) { int res; - tmp = PyObject_GetAttrString(obj, "exc"); + tmp = _PyObject_GetAttrId(obj, &PyId_exc); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &exc, arena); if (res != 0) goto failed; @@ -4312,9 +4377,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { exc = NULL; } - if (PyObject_HasAttrString(obj, "cause")) { + if (_PyObject_HasAttrId(obj, &PyId_cause)) { int res; - tmp = PyObject_GetAttrString(obj, "cause"); + tmp = _PyObject_GetAttrId(obj, &PyId_cause); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &cause, arena); if (res != 0) goto failed; @@ -4337,11 +4402,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* orelse; asdl_seq* finalbody; - if (PyObject_HasAttrString(obj, "body")) { + if (_PyObject_HasAttrId(obj, &PyId_body)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "body"); + tmp = _PyObject_GetAttrId(obj, &PyId_body); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -4362,11 +4427,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); return 1; } - if (PyObject_HasAttrString(obj, "handlers")) { + if (_PyObject_HasAttrId(obj, &PyId_handlers)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "handlers"); + tmp = _PyObject_GetAttrId(obj, &PyId_handlers); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -4387,11 +4452,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); return 1; } - if (PyObject_HasAttrString(obj, "orelse")) { + if (_PyObject_HasAttrId(obj, &PyId_orelse)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "orelse"); + tmp = _PyObject_GetAttrId(obj, &PyId_orelse); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -4412,11 +4477,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); return 1; } - if (PyObject_HasAttrString(obj, "finalbody")) { + if (_PyObject_HasAttrId(obj, &PyId_finalbody)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "finalbody"); + tmp = _PyObject_GetAttrId(obj, &PyId_finalbody); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -4450,9 +4515,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) expr_ty test; expr_ty msg; - if (PyObject_HasAttrString(obj, "test")) { + if (_PyObject_HasAttrId(obj, &PyId_test)) { int res; - tmp = PyObject_GetAttrString(obj, "test"); + tmp = _PyObject_GetAttrId(obj, &PyId_test); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &test, arena); if (res != 0) goto failed; @@ -4462,9 +4527,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); return 1; } - if (PyObject_HasAttrString(obj, "msg")) { + if (_PyObject_HasAttrId(obj, &PyId_msg)) { int res; - tmp = PyObject_GetAttrString(obj, "msg"); + tmp = _PyObject_GetAttrId(obj, &PyId_msg); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &msg, arena); if (res != 0) goto failed; @@ -4484,11 +4549,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (isinstance) { asdl_seq* names; - if (PyObject_HasAttrString(obj, "names")) { + if (_PyObject_HasAttrId(obj, &PyId_names)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "names"); + tmp = _PyObject_GetAttrId(obj, &PyId_names); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -4522,9 +4587,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) asdl_seq* names; int level; - if (PyObject_HasAttrString(obj, "module")) { + if (_PyObject_HasAttrId(obj, &PyId_module)) { int res; - tmp = PyObject_GetAttrString(obj, "module"); + tmp = _PyObject_GetAttrId(obj, &PyId_module); if (tmp == NULL) goto failed; res = obj2ast_identifier(tmp, &module, arena); if (res != 0) goto failed; @@ -4533,11 +4598,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) } else { module = NULL; } - if (PyObject_HasAttrString(obj, "names")) { + if (_PyObject_HasAttrId(obj, &PyId_names)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "names"); + tmp = _PyObject_GetAttrId(obj, &PyId_names); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -4558,9 +4623,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); return 1; } - if (PyObject_HasAttrString(obj, "level")) { + if (_PyObject_HasAttrId(obj, &PyId_level)) { int res; - tmp = PyObject_GetAttrString(obj, "level"); + tmp = _PyObject_GetAttrId(obj, &PyId_level); if (tmp == NULL) goto failed; res = obj2ast_int(tmp, &level, arena); if (res != 0) goto failed; @@ -4581,11 +4646,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (isinstance) { asdl_seq* names; - if (PyObject_HasAttrString(obj, "names")) { + if (_PyObject_HasAttrId(obj, &PyId_names)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "names"); + tmp = _PyObject_GetAttrId(obj, &PyId_names); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -4617,11 +4682,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (isinstance) { asdl_seq* names; - if (PyObject_HasAttrString(obj, "names")) { + if (_PyObject_HasAttrId(obj, &PyId_names)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "names"); + tmp = _PyObject_GetAttrId(obj, &PyId_names); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -4653,9 +4718,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) if (isinstance) { expr_ty value; - if (PyObject_HasAttrString(obj, "value")) { + if (_PyObject_HasAttrId(obj, &PyId_value)) { int res; - tmp = PyObject_GetAttrString(obj, "value"); + tmp = _PyObject_GetAttrId(obj, &PyId_value); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &value, arena); if (res != 0) goto failed; @@ -4719,9 +4784,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) *out = NULL; return 0; } - if (PyObject_HasAttrString(obj, "lineno")) { + if (_PyObject_HasAttrId(obj, &PyId_lineno)) { int res; - tmp = PyObject_GetAttrString(obj, "lineno"); + tmp = _PyObject_GetAttrId(obj, &PyId_lineno); if (tmp == NULL) goto failed; res = obj2ast_int(tmp, &lineno, arena); if (res != 0) goto failed; @@ -4731,9 +4796,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); return 1; } - if (PyObject_HasAttrString(obj, "col_offset")) { + if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { int res; - tmp = PyObject_GetAttrString(obj, "col_offset"); + tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); if (tmp == NULL) goto failed; res = obj2ast_int(tmp, &col_offset, arena); if (res != 0) goto failed; @@ -4751,9 +4816,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) boolop_ty op; asdl_seq* values; - if (PyObject_HasAttrString(obj, "op")) { + if (_PyObject_HasAttrId(obj, &PyId_op)) { int res; - tmp = PyObject_GetAttrString(obj, "op"); + tmp = _PyObject_GetAttrId(obj, &PyId_op); if (tmp == NULL) goto failed; res = obj2ast_boolop(tmp, &op, arena); if (res != 0) goto failed; @@ -4763,11 +4828,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); return 1; } - if (PyObject_HasAttrString(obj, "values")) { + if (_PyObject_HasAttrId(obj, &PyId_values)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "values"); + tmp = _PyObject_GetAttrId(obj, &PyId_values); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -4801,9 +4866,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) operator_ty op; expr_ty right; - if (PyObject_HasAttrString(obj, "left")) { + if (_PyObject_HasAttrId(obj, &PyId_left)) { int res; - tmp = PyObject_GetAttrString(obj, "left"); + tmp = _PyObject_GetAttrId(obj, &PyId_left); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &left, arena); if (res != 0) goto failed; @@ -4813,9 +4878,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); return 1; } - if (PyObject_HasAttrString(obj, "op")) { + if (_PyObject_HasAttrId(obj, &PyId_op)) { int res; - tmp = PyObject_GetAttrString(obj, "op"); + tmp = _PyObject_GetAttrId(obj, &PyId_op); if (tmp == NULL) goto failed; res = obj2ast_operator(tmp, &op, arena); if (res != 0) goto failed; @@ -4825,9 +4890,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); return 1; } - if (PyObject_HasAttrString(obj, "right")) { + if (_PyObject_HasAttrId(obj, &PyId_right)) { int res; - tmp = PyObject_GetAttrString(obj, "right"); + tmp = _PyObject_GetAttrId(obj, &PyId_right); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &right, arena); if (res != 0) goto failed; @@ -4849,9 +4914,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) unaryop_ty op; expr_ty operand; - if (PyObject_HasAttrString(obj, "op")) { + if (_PyObject_HasAttrId(obj, &PyId_op)) { int res; - tmp = PyObject_GetAttrString(obj, "op"); + tmp = _PyObject_GetAttrId(obj, &PyId_op); if (tmp == NULL) goto failed; res = obj2ast_unaryop(tmp, &op, arena); if (res != 0) goto failed; @@ -4861,9 +4926,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); return 1; } - if (PyObject_HasAttrString(obj, "operand")) { + if (_PyObject_HasAttrId(obj, &PyId_operand)) { int res; - tmp = PyObject_GetAttrString(obj, "operand"); + tmp = _PyObject_GetAttrId(obj, &PyId_operand); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &operand, arena); if (res != 0) goto failed; @@ -4885,9 +4950,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) arguments_ty args; expr_ty body; - if (PyObject_HasAttrString(obj, "args")) { + if (_PyObject_HasAttrId(obj, &PyId_args)) { int res; - tmp = PyObject_GetAttrString(obj, "args"); + tmp = _PyObject_GetAttrId(obj, &PyId_args); if (tmp == NULL) goto failed; res = obj2ast_arguments(tmp, &args, arena); if (res != 0) goto failed; @@ -4897,9 +4962,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); return 1; } - if (PyObject_HasAttrString(obj, "body")) { + if (_PyObject_HasAttrId(obj, &PyId_body)) { int res; - tmp = PyObject_GetAttrString(obj, "body"); + tmp = _PyObject_GetAttrId(obj, &PyId_body); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &body, arena); if (res != 0) goto failed; @@ -4922,9 +4987,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty body; expr_ty orelse; - if (PyObject_HasAttrString(obj, "test")) { + if (_PyObject_HasAttrId(obj, &PyId_test)) { int res; - tmp = PyObject_GetAttrString(obj, "test"); + tmp = _PyObject_GetAttrId(obj, &PyId_test); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &test, arena); if (res != 0) goto failed; @@ -4934,9 +4999,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); return 1; } - if (PyObject_HasAttrString(obj, "body")) { + if (_PyObject_HasAttrId(obj, &PyId_body)) { int res; - tmp = PyObject_GetAttrString(obj, "body"); + tmp = _PyObject_GetAttrId(obj, &PyId_body); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &body, arena); if (res != 0) goto failed; @@ -4946,9 +5011,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); return 1; } - if (PyObject_HasAttrString(obj, "orelse")) { + if (_PyObject_HasAttrId(obj, &PyId_orelse)) { int res; - tmp = PyObject_GetAttrString(obj, "orelse"); + tmp = _PyObject_GetAttrId(obj, &PyId_orelse); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &orelse, arena); if (res != 0) goto failed; @@ -4970,11 +5035,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) asdl_seq* keys; asdl_seq* values; - if (PyObject_HasAttrString(obj, "keys")) { + if (_PyObject_HasAttrId(obj, &PyId_keys)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "keys"); + tmp = _PyObject_GetAttrId(obj, &PyId_keys); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -4995,11 +5060,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); return 1; } - if (PyObject_HasAttrString(obj, "values")) { + if (_PyObject_HasAttrId(obj, &PyId_values)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "values"); + tmp = _PyObject_GetAttrId(obj, &PyId_values); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -5031,11 +5096,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (isinstance) { asdl_seq* elts; - if (PyObject_HasAttrString(obj, "elts")) { + if (_PyObject_HasAttrId(obj, &PyId_elts)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "elts"); + tmp = _PyObject_GetAttrId(obj, &PyId_elts); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -5068,9 +5133,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty elt; asdl_seq* generators; - if (PyObject_HasAttrString(obj, "elt")) { + if (_PyObject_HasAttrId(obj, &PyId_elt)) { int res; - tmp = PyObject_GetAttrString(obj, "elt"); + tmp = _PyObject_GetAttrId(obj, &PyId_elt); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &elt, arena); if (res != 0) goto failed; @@ -5080,11 +5145,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); return 1; } - if (PyObject_HasAttrString(obj, "generators")) { + if (_PyObject_HasAttrId(obj, &PyId_generators)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "generators"); + tmp = _PyObject_GetAttrId(obj, &PyId_generators); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -5117,9 +5182,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty elt; asdl_seq* generators; - if (PyObject_HasAttrString(obj, "elt")) { + if (_PyObject_HasAttrId(obj, &PyId_elt)) { int res; - tmp = PyObject_GetAttrString(obj, "elt"); + tmp = _PyObject_GetAttrId(obj, &PyId_elt); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &elt, arena); if (res != 0) goto failed; @@ -5129,11 +5194,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); return 1; } - if (PyObject_HasAttrString(obj, "generators")) { + if (_PyObject_HasAttrId(obj, &PyId_generators)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "generators"); + tmp = _PyObject_GetAttrId(obj, &PyId_generators); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -5167,9 +5232,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty value; asdl_seq* generators; - if (PyObject_HasAttrString(obj, "key")) { + if (_PyObject_HasAttrId(obj, &PyId_key)) { int res; - tmp = PyObject_GetAttrString(obj, "key"); + tmp = _PyObject_GetAttrId(obj, &PyId_key); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &key, arena); if (res != 0) goto failed; @@ -5179,9 +5244,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); return 1; } - if (PyObject_HasAttrString(obj, "value")) { + if (_PyObject_HasAttrId(obj, &PyId_value)) { int res; - tmp = PyObject_GetAttrString(obj, "value"); + tmp = _PyObject_GetAttrId(obj, &PyId_value); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &value, arena); if (res != 0) goto failed; @@ -5191,11 +5256,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); return 1; } - if (PyObject_HasAttrString(obj, "generators")) { + if (_PyObject_HasAttrId(obj, &PyId_generators)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "generators"); + tmp = _PyObject_GetAttrId(obj, &PyId_generators); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -5229,9 +5294,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty elt; asdl_seq* generators; - if (PyObject_HasAttrString(obj, "elt")) { + if (_PyObject_HasAttrId(obj, &PyId_elt)) { int res; - tmp = PyObject_GetAttrString(obj, "elt"); + tmp = _PyObject_GetAttrId(obj, &PyId_elt); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &elt, arena); if (res != 0) goto failed; @@ -5241,11 +5306,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); return 1; } - if (PyObject_HasAttrString(obj, "generators")) { + if (_PyObject_HasAttrId(obj, &PyId_generators)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "generators"); + tmp = _PyObject_GetAttrId(obj, &PyId_generators); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -5277,9 +5342,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (isinstance) { expr_ty value; - if (PyObject_HasAttrString(obj, "value")) { + if (_PyObject_HasAttrId(obj, &PyId_value)) { int res; - tmp = PyObject_GetAttrString(obj, "value"); + tmp = _PyObject_GetAttrId(obj, &PyId_value); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &value, arena); if (res != 0) goto failed; @@ -5301,9 +5366,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) asdl_int_seq* ops; asdl_seq* comparators; - if (PyObject_HasAttrString(obj, "left")) { + if (_PyObject_HasAttrId(obj, &PyId_left)) { int res; - tmp = PyObject_GetAttrString(obj, "left"); + tmp = _PyObject_GetAttrId(obj, &PyId_left); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &left, arena); if (res != 0) goto failed; @@ -5313,11 +5378,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); return 1; } - if (PyObject_HasAttrString(obj, "ops")) { + if (_PyObject_HasAttrId(obj, &PyId_ops)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "ops"); + tmp = _PyObject_GetAttrId(obj, &PyId_ops); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -5338,11 +5403,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); return 1; } - if (PyObject_HasAttrString(obj, "comparators")) { + if (_PyObject_HasAttrId(obj, &PyId_comparators)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "comparators"); + tmp = _PyObject_GetAttrId(obj, &PyId_comparators); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -5379,9 +5444,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty starargs; expr_ty kwargs; - if (PyObject_HasAttrString(obj, "func")) { + if (_PyObject_HasAttrId(obj, &PyId_func)) { int res; - tmp = PyObject_GetAttrString(obj, "func"); + tmp = _PyObject_GetAttrId(obj, &PyId_func); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &func, arena); if (res != 0) goto failed; @@ -5391,11 +5456,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); return 1; } - if (PyObject_HasAttrString(obj, "args")) { + if (_PyObject_HasAttrId(obj, &PyId_args)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "args"); + tmp = _PyObject_GetAttrId(obj, &PyId_args); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -5416,11 +5481,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); return 1; } - if (PyObject_HasAttrString(obj, "keywords")) { + if (_PyObject_HasAttrId(obj, &PyId_keywords)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "keywords"); + tmp = _PyObject_GetAttrId(obj, &PyId_keywords); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -5441,9 +5506,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); return 1; } - if (PyObject_HasAttrString(obj, "starargs")) { + if (_PyObject_HasAttrId(obj, &PyId_starargs)) { int res; - tmp = PyObject_GetAttrString(obj, "starargs"); + tmp = _PyObject_GetAttrId(obj, &PyId_starargs); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &starargs, arena); if (res != 0) goto failed; @@ -5452,9 +5517,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { starargs = NULL; } - if (PyObject_HasAttrString(obj, "kwargs")) { + if (_PyObject_HasAttrId(obj, &PyId_kwargs)) { int res; - tmp = PyObject_GetAttrString(obj, "kwargs"); + tmp = _PyObject_GetAttrId(obj, &PyId_kwargs); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &kwargs, arena); if (res != 0) goto failed; @@ -5475,9 +5540,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (isinstance) { object n; - if (PyObject_HasAttrString(obj, "n")) { + if (_PyObject_HasAttrId(obj, &PyId_n)) { int res; - tmp = PyObject_GetAttrString(obj, "n"); + tmp = _PyObject_GetAttrId(obj, &PyId_n); if (tmp == NULL) goto failed; res = obj2ast_object(tmp, &n, arena); if (res != 0) goto failed; @@ -5498,9 +5563,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (isinstance) { string s; - if (PyObject_HasAttrString(obj, "s")) { + if (_PyObject_HasAttrId(obj, &PyId_s)) { int res; - tmp = PyObject_GetAttrString(obj, "s"); + tmp = _PyObject_GetAttrId(obj, &PyId_s); if (tmp == NULL) goto failed; res = obj2ast_string(tmp, &s, arena); if (res != 0) goto failed; @@ -5521,9 +5586,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) if (isinstance) { bytes s; - if (PyObject_HasAttrString(obj, "s")) { + if (_PyObject_HasAttrId(obj, &PyId_s)) { int res; - tmp = PyObject_GetAttrString(obj, "s"); + tmp = _PyObject_GetAttrId(obj, &PyId_s); if (tmp == NULL) goto failed; res = obj2ast_bytes(tmp, &s, arena); if (res != 0) goto failed; @@ -5556,9 +5621,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) identifier attr; expr_context_ty ctx; - if (PyObject_HasAttrString(obj, "value")) { + if (_PyObject_HasAttrId(obj, &PyId_value)) { int res; - tmp = PyObject_GetAttrString(obj, "value"); + tmp = _PyObject_GetAttrId(obj, &PyId_value); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &value, arena); if (res != 0) goto failed; @@ -5568,9 +5633,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); return 1; } - if (PyObject_HasAttrString(obj, "attr")) { + if (_PyObject_HasAttrId(obj, &PyId_attr)) { int res; - tmp = PyObject_GetAttrString(obj, "attr"); + tmp = _PyObject_GetAttrId(obj, &PyId_attr); if (tmp == NULL) goto failed; res = obj2ast_identifier(tmp, &attr, arena); if (res != 0) goto failed; @@ -5580,9 +5645,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); return 1; } - if (PyObject_HasAttrString(obj, "ctx")) { + if (_PyObject_HasAttrId(obj, &PyId_ctx)) { int res; - tmp = PyObject_GetAttrString(obj, "ctx"); + tmp = _PyObject_GetAttrId(obj, &PyId_ctx); if (tmp == NULL) goto failed; res = obj2ast_expr_context(tmp, &ctx, arena); if (res != 0) goto failed; @@ -5605,9 +5670,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) slice_ty slice; expr_context_ty ctx; - if (PyObject_HasAttrString(obj, "value")) { + if (_PyObject_HasAttrId(obj, &PyId_value)) { int res; - tmp = PyObject_GetAttrString(obj, "value"); + tmp = _PyObject_GetAttrId(obj, &PyId_value); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &value, arena); if (res != 0) goto failed; @@ -5617,9 +5682,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); return 1; } - if (PyObject_HasAttrString(obj, "slice")) { + if (_PyObject_HasAttrId(obj, &PyId_slice)) { int res; - tmp = PyObject_GetAttrString(obj, "slice"); + tmp = _PyObject_GetAttrId(obj, &PyId_slice); if (tmp == NULL) goto failed; res = obj2ast_slice(tmp, &slice, arena); if (res != 0) goto failed; @@ -5629,9 +5694,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); return 1; } - if (PyObject_HasAttrString(obj, "ctx")) { + if (_PyObject_HasAttrId(obj, &PyId_ctx)) { int res; - tmp = PyObject_GetAttrString(obj, "ctx"); + tmp = _PyObject_GetAttrId(obj, &PyId_ctx); if (tmp == NULL) goto failed; res = obj2ast_expr_context(tmp, &ctx, arena); if (res != 0) goto failed; @@ -5653,9 +5718,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) expr_ty value; expr_context_ty ctx; - if (PyObject_HasAttrString(obj, "value")) { + if (_PyObject_HasAttrId(obj, &PyId_value)) { int res; - tmp = PyObject_GetAttrString(obj, "value"); + tmp = _PyObject_GetAttrId(obj, &PyId_value); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &value, arena); if (res != 0) goto failed; @@ -5665,9 +5730,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); return 1; } - if (PyObject_HasAttrString(obj, "ctx")) { + if (_PyObject_HasAttrId(obj, &PyId_ctx)) { int res; - tmp = PyObject_GetAttrString(obj, "ctx"); + tmp = _PyObject_GetAttrId(obj, &PyId_ctx); if (tmp == NULL) goto failed; res = obj2ast_expr_context(tmp, &ctx, arena); if (res != 0) goto failed; @@ -5689,9 +5754,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) identifier id; expr_context_ty ctx; - if (PyObject_HasAttrString(obj, "id")) { + if (_PyObject_HasAttrId(obj, &PyId_id)) { int res; - tmp = PyObject_GetAttrString(obj, "id"); + tmp = _PyObject_GetAttrId(obj, &PyId_id); if (tmp == NULL) goto failed; res = obj2ast_identifier(tmp, &id, arena); if (res != 0) goto failed; @@ -5701,9 +5766,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); return 1; } - if (PyObject_HasAttrString(obj, "ctx")) { + if (_PyObject_HasAttrId(obj, &PyId_ctx)) { int res; - tmp = PyObject_GetAttrString(obj, "ctx"); + tmp = _PyObject_GetAttrId(obj, &PyId_ctx); if (tmp == NULL) goto failed; res = obj2ast_expr_context(tmp, &ctx, arena); if (res != 0) goto failed; @@ -5725,11 +5790,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) asdl_seq* elts; expr_context_ty ctx; - if (PyObject_HasAttrString(obj, "elts")) { + if (_PyObject_HasAttrId(obj, &PyId_elts)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "elts"); + tmp = _PyObject_GetAttrId(obj, &PyId_elts); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -5750,9 +5815,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); return 1; } - if (PyObject_HasAttrString(obj, "ctx")) { + if (_PyObject_HasAttrId(obj, &PyId_ctx)) { int res; - tmp = PyObject_GetAttrString(obj, "ctx"); + tmp = _PyObject_GetAttrId(obj, &PyId_ctx); if (tmp == NULL) goto failed; res = obj2ast_expr_context(tmp, &ctx, arena); if (res != 0) goto failed; @@ -5774,11 +5839,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) asdl_seq* elts; expr_context_ty ctx; - if (PyObject_HasAttrString(obj, "elts")) { + if (_PyObject_HasAttrId(obj, &PyId_elts)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "elts"); + tmp = _PyObject_GetAttrId(obj, &PyId_elts); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -5799,9 +5864,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); return 1; } - if (PyObject_HasAttrString(obj, "ctx")) { + if (_PyObject_HasAttrId(obj, &PyId_ctx)) { int res; - tmp = PyObject_GetAttrString(obj, "ctx"); + tmp = _PyObject_GetAttrId(obj, &PyId_ctx); if (tmp == NULL) goto failed; res = obj2ast_expr_context(tmp, &ctx, arena); if (res != 0) goto failed; @@ -5900,9 +5965,9 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) expr_ty upper; expr_ty step; - if (PyObject_HasAttrString(obj, "lower")) { + if (_PyObject_HasAttrId(obj, &PyId_lower)) { int res; - tmp = PyObject_GetAttrString(obj, "lower"); + tmp = _PyObject_GetAttrId(obj, &PyId_lower); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &lower, arena); if (res != 0) goto failed; @@ -5911,9 +5976,9 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) } else { lower = NULL; } - if (PyObject_HasAttrString(obj, "upper")) { + if (_PyObject_HasAttrId(obj, &PyId_upper)) { int res; - tmp = PyObject_GetAttrString(obj, "upper"); + tmp = _PyObject_GetAttrId(obj, &PyId_upper); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &upper, arena); if (res != 0) goto failed; @@ -5922,9 +5987,9 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) } else { upper = NULL; } - if (PyObject_HasAttrString(obj, "step")) { + if (_PyObject_HasAttrId(obj, &PyId_step)) { int res; - tmp = PyObject_GetAttrString(obj, "step"); + tmp = _PyObject_GetAttrId(obj, &PyId_step); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &step, arena); if (res != 0) goto failed; @@ -5944,11 +6009,11 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) if (isinstance) { asdl_seq* dims; - if (PyObject_HasAttrString(obj, "dims")) { + if (_PyObject_HasAttrId(obj, &PyId_dims)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "dims"); + tmp = _PyObject_GetAttrId(obj, &PyId_dims); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -5980,9 +6045,9 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) if (isinstance) { expr_ty value; - if (PyObject_HasAttrString(obj, "value")) { + if (_PyObject_HasAttrId(obj, &PyId_value)) { int res; - tmp = PyObject_GetAttrString(obj, "value"); + tmp = _PyObject_GetAttrId(obj, &PyId_value); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &value, arena); if (res != 0) goto failed; @@ -6275,9 +6340,9 @@ obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) expr_ty iter; asdl_seq* ifs; - if (PyObject_HasAttrString(obj, "target")) { + if (_PyObject_HasAttrId(obj, &PyId_target)) { int res; - tmp = PyObject_GetAttrString(obj, "target"); + tmp = _PyObject_GetAttrId(obj, &PyId_target); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &target, arena); if (res != 0) goto failed; @@ -6287,9 +6352,9 @@ obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); return 1; } - if (PyObject_HasAttrString(obj, "iter")) { + if (_PyObject_HasAttrId(obj, &PyId_iter)) { int res; - tmp = PyObject_GetAttrString(obj, "iter"); + tmp = _PyObject_GetAttrId(obj, &PyId_iter); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &iter, arena); if (res != 0) goto failed; @@ -6299,11 +6364,11 @@ obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); return 1; } - if (PyObject_HasAttrString(obj, "ifs")) { + if (_PyObject_HasAttrId(obj, &PyId_ifs)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "ifs"); + tmp = _PyObject_GetAttrId(obj, &PyId_ifs); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -6344,9 +6409,9 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) *out = NULL; return 0; } - if (PyObject_HasAttrString(obj, "lineno")) { + if (_PyObject_HasAttrId(obj, &PyId_lineno)) { int res; - tmp = PyObject_GetAttrString(obj, "lineno"); + tmp = _PyObject_GetAttrId(obj, &PyId_lineno); if (tmp == NULL) goto failed; res = obj2ast_int(tmp, &lineno, arena); if (res != 0) goto failed; @@ -6356,9 +6421,9 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); return 1; } - if (PyObject_HasAttrString(obj, "col_offset")) { + if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { int res; - tmp = PyObject_GetAttrString(obj, "col_offset"); + tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); if (tmp == NULL) goto failed; res = obj2ast_int(tmp, &col_offset, arena); if (res != 0) goto failed; @@ -6377,9 +6442,9 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) identifier name; asdl_seq* body; - if (PyObject_HasAttrString(obj, "type")) { + if (_PyObject_HasAttrId(obj, &PyId_type)) { int res; - tmp = PyObject_GetAttrString(obj, "type"); + tmp = _PyObject_GetAttrId(obj, &PyId_type); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &type, arena); if (res != 0) goto failed; @@ -6388,9 +6453,9 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) } else { type = NULL; } - if (PyObject_HasAttrString(obj, "name")) { + if (_PyObject_HasAttrId(obj, &PyId_name)) { int res; - tmp = PyObject_GetAttrString(obj, "name"); + tmp = _PyObject_GetAttrId(obj, &PyId_name); if (tmp == NULL) goto failed; res = obj2ast_identifier(tmp, &name, arena); if (res != 0) goto failed; @@ -6399,11 +6464,11 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) } else { name = NULL; } - if (PyObject_HasAttrString(obj, "body")) { + if (_PyObject_HasAttrId(obj, &PyId_body)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "body"); + tmp = _PyObject_GetAttrId(obj, &PyId_body); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -6449,11 +6514,11 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) asdl_seq* defaults; asdl_seq* kw_defaults; - if (PyObject_HasAttrString(obj, "args")) { + if (_PyObject_HasAttrId(obj, &PyId_args)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "args"); + tmp = _PyObject_GetAttrId(obj, &PyId_args); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -6474,9 +6539,9 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); return 1; } - if (PyObject_HasAttrString(obj, "vararg")) { + if (_PyObject_HasAttrId(obj, &PyId_vararg)) { int res; - tmp = PyObject_GetAttrString(obj, "vararg"); + tmp = _PyObject_GetAttrId(obj, &PyId_vararg); if (tmp == NULL) goto failed; res = obj2ast_identifier(tmp, &vararg, arena); if (res != 0) goto failed; @@ -6485,9 +6550,9 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) } else { vararg = NULL; } - if (PyObject_HasAttrString(obj, "varargannotation")) { + if (_PyObject_HasAttrId(obj, &PyId_varargannotation)) { int res; - tmp = PyObject_GetAttrString(obj, "varargannotation"); + tmp = _PyObject_GetAttrId(obj, &PyId_varargannotation); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &varargannotation, arena); if (res != 0) goto failed; @@ -6496,11 +6561,11 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) } else { varargannotation = NULL; } - if (PyObject_HasAttrString(obj, "kwonlyargs")) { + if (_PyObject_HasAttrId(obj, &PyId_kwonlyargs)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "kwonlyargs"); + tmp = _PyObject_GetAttrId(obj, &PyId_kwonlyargs); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -6521,9 +6586,9 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); return 1; } - if (PyObject_HasAttrString(obj, "kwarg")) { + if (_PyObject_HasAttrId(obj, &PyId_kwarg)) { int res; - tmp = PyObject_GetAttrString(obj, "kwarg"); + tmp = _PyObject_GetAttrId(obj, &PyId_kwarg); if (tmp == NULL) goto failed; res = obj2ast_identifier(tmp, &kwarg, arena); if (res != 0) goto failed; @@ -6532,9 +6597,9 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) } else { kwarg = NULL; } - if (PyObject_HasAttrString(obj, "kwargannotation")) { + if (_PyObject_HasAttrId(obj, &PyId_kwargannotation)) { int res; - tmp = PyObject_GetAttrString(obj, "kwargannotation"); + tmp = _PyObject_GetAttrId(obj, &PyId_kwargannotation); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &kwargannotation, arena); if (res != 0) goto failed; @@ -6543,11 +6608,11 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) } else { kwargannotation = NULL; } - if (PyObject_HasAttrString(obj, "defaults")) { + if (_PyObject_HasAttrId(obj, &PyId_defaults)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "defaults"); + tmp = _PyObject_GetAttrId(obj, &PyId_defaults); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -6568,11 +6633,11 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); return 1; } - if (PyObject_HasAttrString(obj, "kw_defaults")) { + if (_PyObject_HasAttrId(obj, &PyId_kw_defaults)) { int res; Py_ssize_t len; Py_ssize_t i; - tmp = PyObject_GetAttrString(obj, "kw_defaults"); + tmp = _PyObject_GetAttrId(obj, &PyId_kw_defaults); if (tmp == NULL) goto failed; if (!PyList_Check(tmp)) { PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); @@ -6608,9 +6673,9 @@ obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) identifier arg; expr_ty annotation; - if (PyObject_HasAttrString(obj, "arg")) { + if (_PyObject_HasAttrId(obj, &PyId_arg)) { int res; - tmp = PyObject_GetAttrString(obj, "arg"); + tmp = _PyObject_GetAttrId(obj, &PyId_arg); if (tmp == NULL) goto failed; res = obj2ast_identifier(tmp, &arg, arena); if (res != 0) goto failed; @@ -6620,9 +6685,9 @@ obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); return 1; } - if (PyObject_HasAttrString(obj, "annotation")) { + if (_PyObject_HasAttrId(obj, &PyId_annotation)) { int res; - tmp = PyObject_GetAttrString(obj, "annotation"); + tmp = _PyObject_GetAttrId(obj, &PyId_annotation); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &annotation, arena); if (res != 0) goto failed; @@ -6645,9 +6710,9 @@ obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) identifier arg; expr_ty value; - if (PyObject_HasAttrString(obj, "arg")) { + if (_PyObject_HasAttrId(obj, &PyId_arg)) { int res; - tmp = PyObject_GetAttrString(obj, "arg"); + tmp = _PyObject_GetAttrId(obj, &PyId_arg); if (tmp == NULL) goto failed; res = obj2ast_identifier(tmp, &arg, arena); if (res != 0) goto failed; @@ -6657,9 +6722,9 @@ obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword"); return 1; } - if (PyObject_HasAttrString(obj, "value")) { + if (_PyObject_HasAttrId(obj, &PyId_value)) { int res; - tmp = PyObject_GetAttrString(obj, "value"); + tmp = _PyObject_GetAttrId(obj, &PyId_value); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &value, arena); if (res != 0) goto failed; @@ -6683,9 +6748,9 @@ obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) identifier name; identifier asname; - if (PyObject_HasAttrString(obj, "name")) { + if (_PyObject_HasAttrId(obj, &PyId_name)) { int res; - tmp = PyObject_GetAttrString(obj, "name"); + tmp = _PyObject_GetAttrId(obj, &PyId_name); if (tmp == NULL) goto failed; res = obj2ast_identifier(tmp, &name, arena); if (res != 0) goto failed; @@ -6695,9 +6760,9 @@ obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); return 1; } - if (PyObject_HasAttrString(obj, "asname")) { + if (_PyObject_HasAttrId(obj, &PyId_asname)) { int res; - tmp = PyObject_GetAttrString(obj, "asname"); + tmp = _PyObject_GetAttrId(obj, &PyId_asname); if (tmp == NULL) goto failed; res = obj2ast_identifier(tmp, &asname, arena); if (res != 0) goto failed; @@ -6720,9 +6785,9 @@ obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) expr_ty context_expr; expr_ty optional_vars; - if (PyObject_HasAttrString(obj, "context_expr")) { + if (_PyObject_HasAttrId(obj, &PyId_context_expr)) { int res; - tmp = PyObject_GetAttrString(obj, "context_expr"); + tmp = _PyObject_GetAttrId(obj, &PyId_context_expr); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &context_expr, arena); if (res != 0) goto failed; @@ -6732,9 +6797,9 @@ obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); return 1; } - if (PyObject_HasAttrString(obj, "optional_vars")) { + if (_PyObject_HasAttrId(obj, &PyId_optional_vars)) { int res; - tmp = PyObject_GetAttrString(obj, "optional_vars"); + tmp = _PyObject_GetAttrId(obj, &PyId_optional_vars); if (tmp == NULL) goto failed; res = obj2ast_expr(tmp, &optional_vars, arena); if (res != 0) goto failed; -- cgit v1.2.1 From f5ad3b280b43227eb0e3fa63d89490a58ba9c28b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Fri, 14 Oct 2011 10:20:37 +0200 Subject: Rename _Py_identifier to _Py_IDENTIFIER. --- Python/Python-ast.c | 130 ++++++++++++++++++++++++++-------------------------- 1 file changed, 65 insertions(+), 65 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 2ed36cd220..7c0d858d29 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -7,7 +7,7 @@ static PyTypeObject AST_type; static PyTypeObject *mod_type; static PyObject* ast2obj_mod(void*); static PyTypeObject *Module_type; -_Py_identifier(body); +_Py_IDENTIFIER(body); static char *Module_fields[]={ "body", }; @@ -24,18 +24,18 @@ static char *Suite_fields[]={ "body", }; static PyTypeObject *stmt_type; -_Py_identifier(lineno); -_Py_identifier(col_offset); +_Py_IDENTIFIER(lineno); +_Py_IDENTIFIER(col_offset); static char *stmt_attributes[] = { "lineno", "col_offset", }; static PyObject* ast2obj_stmt(void*); static PyTypeObject *FunctionDef_type; -_Py_identifier(name); -_Py_identifier(args); -_Py_identifier(decorator_list); -_Py_identifier(returns); +_Py_IDENTIFIER(name); +_Py_IDENTIFIER(args); +_Py_IDENTIFIER(decorator_list); +_Py_IDENTIFIER(returns); static char *FunctionDef_fields[]={ "name", "args", @@ -44,10 +44,10 @@ static char *FunctionDef_fields[]={ "returns", }; static PyTypeObject *ClassDef_type; -_Py_identifier(bases); -_Py_identifier(keywords); -_Py_identifier(starargs); -_Py_identifier(kwargs); +_Py_IDENTIFIER(bases); +_Py_IDENTIFIER(keywords); +_Py_IDENTIFIER(starargs); +_Py_IDENTIFIER(kwargs); static char *ClassDef_fields[]={ "name", "bases", @@ -58,12 +58,12 @@ static char *ClassDef_fields[]={ "decorator_list", }; static PyTypeObject *Return_type; -_Py_identifier(value); +_Py_IDENTIFIER(value); static char *Return_fields[]={ "value", }; static PyTypeObject *Delete_type; -_Py_identifier(targets); +_Py_IDENTIFIER(targets); static char *Delete_fields[]={ "targets", }; @@ -73,16 +73,16 @@ static char *Assign_fields[]={ "value", }; static PyTypeObject *AugAssign_type; -_Py_identifier(target); -_Py_identifier(op); +_Py_IDENTIFIER(target); +_Py_IDENTIFIER(op); static char *AugAssign_fields[]={ "target", "op", "value", }; static PyTypeObject *For_type; -_Py_identifier(iter); -_Py_identifier(orelse); +_Py_IDENTIFIER(iter); +_Py_IDENTIFIER(orelse); static char *For_fields[]={ "target", "iter", @@ -90,7 +90,7 @@ static char *For_fields[]={ "orelse", }; static PyTypeObject *While_type; -_Py_identifier(test); +_Py_IDENTIFIER(test); static char *While_fields[]={ "test", "body", @@ -103,21 +103,21 @@ static char *If_fields[]={ "orelse", }; static PyTypeObject *With_type; -_Py_identifier(items); +_Py_IDENTIFIER(items); static char *With_fields[]={ "items", "body", }; static PyTypeObject *Raise_type; -_Py_identifier(exc); -_Py_identifier(cause); +_Py_IDENTIFIER(exc); +_Py_IDENTIFIER(cause); static char *Raise_fields[]={ "exc", "cause", }; static PyTypeObject *Try_type; -_Py_identifier(handlers); -_Py_identifier(finalbody); +_Py_IDENTIFIER(handlers); +_Py_IDENTIFIER(finalbody); static char *Try_fields[]={ "body", "handlers", @@ -125,19 +125,19 @@ static char *Try_fields[]={ "finalbody", }; static PyTypeObject *Assert_type; -_Py_identifier(msg); +_Py_IDENTIFIER(msg); static char *Assert_fields[]={ "test", "msg", }; static PyTypeObject *Import_type; -_Py_identifier(names); +_Py_IDENTIFIER(names); static char *Import_fields[]={ "names", }; static PyTypeObject *ImportFrom_type; -_Py_identifier(module); -_Py_identifier(level); +_Py_IDENTIFIER(module); +_Py_IDENTIFIER(level); static char *ImportFrom_fields[]={ "module", "names", @@ -165,21 +165,21 @@ static char *expr_attributes[] = { }; static PyObject* ast2obj_expr(void*); static PyTypeObject *BoolOp_type; -_Py_identifier(values); +_Py_IDENTIFIER(values); static char *BoolOp_fields[]={ "op", "values", }; static PyTypeObject *BinOp_type; -_Py_identifier(left); -_Py_identifier(right); +_Py_IDENTIFIER(left); +_Py_IDENTIFIER(right); static char *BinOp_fields[]={ "left", "op", "right", }; static PyTypeObject *UnaryOp_type; -_Py_identifier(operand); +_Py_IDENTIFIER(operand); static char *UnaryOp_fields[]={ "op", "operand", @@ -196,19 +196,19 @@ static char *IfExp_fields[]={ "orelse", }; static PyTypeObject *Dict_type; -_Py_identifier(keys); +_Py_IDENTIFIER(keys); static char *Dict_fields[]={ "keys", "values", }; static PyTypeObject *Set_type; -_Py_identifier(elts); +_Py_IDENTIFIER(elts); static char *Set_fields[]={ "elts", }; static PyTypeObject *ListComp_type; -_Py_identifier(elt); -_Py_identifier(generators); +_Py_IDENTIFIER(elt); +_Py_IDENTIFIER(generators); static char *ListComp_fields[]={ "elt", "generators", @@ -219,7 +219,7 @@ static char *SetComp_fields[]={ "generators", }; static PyTypeObject *DictComp_type; -_Py_identifier(key); +_Py_IDENTIFIER(key); static char *DictComp_fields[]={ "key", "value", @@ -235,15 +235,15 @@ static char *Yield_fields[]={ "value", }; static PyTypeObject *Compare_type; -_Py_identifier(ops); -_Py_identifier(comparators); +_Py_IDENTIFIER(ops); +_Py_IDENTIFIER(comparators); static char *Compare_fields[]={ "left", "ops", "comparators", }; static PyTypeObject *Call_type; -_Py_identifier(func); +_Py_IDENTIFIER(func); static char *Call_fields[]={ "func", "args", @@ -252,12 +252,12 @@ static char *Call_fields[]={ "kwargs", }; static PyTypeObject *Num_type; -_Py_identifier(n); +_Py_IDENTIFIER(n); static char *Num_fields[]={ "n", }; static PyTypeObject *Str_type; -_Py_identifier(s); +_Py_IDENTIFIER(s); static char *Str_fields[]={ "s", }; @@ -267,15 +267,15 @@ static char *Bytes_fields[]={ }; static PyTypeObject *Ellipsis_type; static PyTypeObject *Attribute_type; -_Py_identifier(attr); -_Py_identifier(ctx); +_Py_IDENTIFIER(attr); +_Py_IDENTIFIER(ctx); static char *Attribute_fields[]={ "value", "attr", "ctx", }; static PyTypeObject *Subscript_type; -_Py_identifier(slice); +_Py_IDENTIFIER(slice); static char *Subscript_fields[]={ "value", "slice", @@ -287,7 +287,7 @@ static char *Starred_fields[]={ "ctx", }; static PyTypeObject *Name_type; -_Py_identifier(id); +_Py_IDENTIFIER(id); static char *Name_fields[]={ "id", "ctx", @@ -315,16 +315,16 @@ static PyTypeObject *Param_type; static PyTypeObject *slice_type; static PyObject* ast2obj_slice(void*); static PyTypeObject *Slice_type; -_Py_identifier(lower); -_Py_identifier(upper); -_Py_identifier(step); +_Py_IDENTIFIER(lower); +_Py_IDENTIFIER(upper); +_Py_IDENTIFIER(step); static char *Slice_fields[]={ "lower", "upper", "step", }; static PyTypeObject *ExtSlice_type; -_Py_identifier(dims); +_Py_IDENTIFIER(dims); static char *ExtSlice_fields[]={ "dims", }; @@ -380,7 +380,7 @@ static PyTypeObject *In_type; static PyTypeObject *NotIn_type; static PyTypeObject *comprehension_type; static PyObject* ast2obj_comprehension(void*); -_Py_identifier(ifs); +_Py_IDENTIFIER(ifs); static char *comprehension_fields[]={ "target", "iter", @@ -393,7 +393,7 @@ static char *excepthandler_attributes[] = { }; static PyObject* ast2obj_excepthandler(void*); static PyTypeObject *ExceptHandler_type; -_Py_identifier(type); +_Py_IDENTIFIER(type); static char *ExceptHandler_fields[]={ "type", "name", @@ -401,13 +401,13 @@ static char *ExceptHandler_fields[]={ }; static PyTypeObject *arguments_type; static PyObject* ast2obj_arguments(void*); -_Py_identifier(vararg); -_Py_identifier(varargannotation); -_Py_identifier(kwonlyargs); -_Py_identifier(kwarg); -_Py_identifier(kwargannotation); -_Py_identifier(defaults); -_Py_identifier(kw_defaults); +_Py_IDENTIFIER(vararg); +_Py_IDENTIFIER(varargannotation); +_Py_IDENTIFIER(kwonlyargs); +_Py_IDENTIFIER(kwarg); +_Py_IDENTIFIER(kwargannotation); +_Py_IDENTIFIER(defaults); +_Py_IDENTIFIER(kw_defaults); static char *arguments_fields[]={ "args", "vararg", @@ -420,8 +420,8 @@ static char *arguments_fields[]={ }; static PyTypeObject *arg_type; static PyObject* ast2obj_arg(void*); -_Py_identifier(arg); -_Py_identifier(annotation); +_Py_IDENTIFIER(arg); +_Py_IDENTIFIER(annotation); static char *arg_fields[]={ "arg", "annotation", @@ -434,15 +434,15 @@ static char *keyword_fields[]={ }; static PyTypeObject *alias_type; static PyObject* ast2obj_alias(void*); -_Py_identifier(asname); +_Py_IDENTIFIER(asname); static char *alias_fields[]={ "name", "asname", }; static PyTypeObject *withitem_type; static PyObject* ast2obj_withitem(void*); -_Py_identifier(context_expr); -_Py_identifier(optional_vars); +_Py_IDENTIFIER(context_expr); +_Py_IDENTIFIER(optional_vars); static char *withitem_fields[]={ "context_expr", "optional_vars", @@ -452,7 +452,7 @@ static char *withitem_fields[]={ static int ast_type_init(PyObject *self, PyObject *args, PyObject *kw) { - _Py_identifier(_fields); + _Py_IDENTIFIER(_fields); Py_ssize_t i, numfields = 0; int res = -1; PyObject *key, *value, *fields; @@ -506,7 +506,7 @@ static PyObject * ast_type_reduce(PyObject *self, PyObject *unused) { PyObject *res; - _Py_identifier(__dict__); + _Py_IDENTIFIER(__dict__); PyObject *dict = _PyObject_GetAttrId(self, &PyId___dict__); if (dict == NULL) { if (PyErr_ExceptionMatches(PyExc_AttributeError)) -- cgit v1.2.1 From 406e4d8f1d3d003e8754d9e65607a697e7f5c865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Fri, 14 Oct 2011 15:16:45 +0200 Subject: Port SetAttrString/HasAttrString to SetAttrId/GetAttrId. --- Python/Python-ast.c | 269 ++++++++++++++++++++++++++-------------------------- 1 file changed, 135 insertions(+), 134 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 7c0d858d29..3cfb8a87aa 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -593,6 +593,7 @@ static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) { int i, result; + _Py_IDENTIFIER(_attributes); PyObject *s, *l = PyTuple_New(num_fields); if (!l) return 0; @@ -604,7 +605,7 @@ static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) } PyTuple_SET_ITEM(l, i, s); } - result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0; + result = _PyObject_SetAttrId((PyObject*)type, &PyId__attributes, l) >= 0; Py_DECREF(l); return result; } @@ -2230,7 +2231,7 @@ ast2obj_mod(void* _o) if (!result) goto failed; value = ast2obj_list(o->v.Module.body, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttrString(result, "body", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) goto failed; Py_DECREF(value); break; @@ -2239,7 +2240,7 @@ ast2obj_mod(void* _o) if (!result) goto failed; value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttrString(result, "body", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) goto failed; Py_DECREF(value); break; @@ -2248,7 +2249,7 @@ ast2obj_mod(void* _o) if (!result) goto failed; value = ast2obj_expr(o->v.Expression.body); if (!value) goto failed; - if (PyObject_SetAttrString(result, "body", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) goto failed; Py_DECREF(value); break; @@ -2257,7 +2258,7 @@ ast2obj_mod(void* _o) if (!result) goto failed; value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttrString(result, "body", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) goto failed; Py_DECREF(value); break; @@ -2285,29 +2286,29 @@ ast2obj_stmt(void* _o) if (!result) goto failed; value = ast2obj_identifier(o->v.FunctionDef.name); if (!value) goto failed; - if (PyObject_SetAttrString(result, "name", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_arguments(o->v.FunctionDef.args); if (!value) goto failed; - if (PyObject_SetAttrString(result, "args", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttrString(result, "body", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttrString(result, "decorator_list", value) == + if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.FunctionDef.returns); if (!value) goto failed; - if (PyObject_SetAttrString(result, "returns", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) goto failed; Py_DECREF(value); break; @@ -2316,38 +2317,38 @@ ast2obj_stmt(void* _o) if (!result) goto failed; value = ast2obj_identifier(o->v.ClassDef.name); if (!value) goto failed; - if (PyObject_SetAttrString(result, "name", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttrString(result, "bases", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_bases, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); if (!value) goto failed; - if (PyObject_SetAttrString(result, "keywords", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.ClassDef.starargs); if (!value) goto failed; - if (PyObject_SetAttrString(result, "starargs", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_starargs, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.ClassDef.kwargs); if (!value) goto failed; - if (PyObject_SetAttrString(result, "kwargs", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_kwargs, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttrString(result, "body", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttrString(result, "decorator_list", value) == + if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) goto failed; Py_DECREF(value); @@ -2357,7 +2358,7 @@ ast2obj_stmt(void* _o) if (!result) goto failed; value = ast2obj_expr(o->v.Return.value); if (!value) goto failed; - if (PyObject_SetAttrString(result, "value", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) goto failed; Py_DECREF(value); break; @@ -2366,7 +2367,7 @@ ast2obj_stmt(void* _o) if (!result) goto failed; value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttrString(result, "targets", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) goto failed; Py_DECREF(value); break; @@ -2375,12 +2376,12 @@ ast2obj_stmt(void* _o) if (!result) goto failed; value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttrString(result, "targets", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.Assign.value); if (!value) goto failed; - if (PyObject_SetAttrString(result, "value", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) goto failed; Py_DECREF(value); break; @@ -2389,17 +2390,17 @@ ast2obj_stmt(void* _o) if (!result) goto failed; value = ast2obj_expr(o->v.AugAssign.target); if (!value) goto failed; - if (PyObject_SetAttrString(result, "target", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_operator(o->v.AugAssign.op); if (!value) goto failed; - if (PyObject_SetAttrString(result, "op", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.AugAssign.value); if (!value) goto failed; - if (PyObject_SetAttrString(result, "value", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) goto failed; Py_DECREF(value); break; @@ -2408,22 +2409,22 @@ ast2obj_stmt(void* _o) if (!result) goto failed; value = ast2obj_expr(o->v.For.target); if (!value) goto failed; - if (PyObject_SetAttrString(result, "target", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.For.iter); if (!value) goto failed; - if (PyObject_SetAttrString(result, "iter", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.For.body, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttrString(result, "body", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttrString(result, "orelse", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) goto failed; Py_DECREF(value); break; @@ -2432,17 +2433,17 @@ ast2obj_stmt(void* _o) if (!result) goto failed; value = ast2obj_expr(o->v.While.test); if (!value) goto failed; - if (PyObject_SetAttrString(result, "test", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.While.body, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttrString(result, "body", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttrString(result, "orelse", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) goto failed; Py_DECREF(value); break; @@ -2451,17 +2452,17 @@ ast2obj_stmt(void* _o) if (!result) goto failed; value = ast2obj_expr(o->v.If.test); if (!value) goto failed; - if (PyObject_SetAttrString(result, "test", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.If.body, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttrString(result, "body", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttrString(result, "orelse", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) goto failed; Py_DECREF(value); break; @@ -2470,12 +2471,12 @@ ast2obj_stmt(void* _o) if (!result) goto failed; value = ast2obj_list(o->v.With.items, ast2obj_withitem); if (!value) goto failed; - if (PyObject_SetAttrString(result, "items", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.With.body, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttrString(result, "body", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) goto failed; Py_DECREF(value); break; @@ -2484,12 +2485,12 @@ ast2obj_stmt(void* _o) if (!result) goto failed; value = ast2obj_expr(o->v.Raise.exc); if (!value) goto failed; - if (PyObject_SetAttrString(result, "exc", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_exc, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.Raise.cause); if (!value) goto failed; - if (PyObject_SetAttrString(result, "cause", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_cause, value) == -1) goto failed; Py_DECREF(value); break; @@ -2498,22 +2499,22 @@ ast2obj_stmt(void* _o) if (!result) goto failed; value = ast2obj_list(o->v.Try.body, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttrString(result, "body", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); if (!value) goto failed; - if (PyObject_SetAttrString(result, "handlers", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_handlers, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttrString(result, "orelse", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttrString(result, "finalbody", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_finalbody, value) == -1) goto failed; Py_DECREF(value); break; @@ -2522,12 +2523,12 @@ ast2obj_stmt(void* _o) if (!result) goto failed; value = ast2obj_expr(o->v.Assert.test); if (!value) goto failed; - if (PyObject_SetAttrString(result, "test", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.Assert.msg); if (!value) goto failed; - if (PyObject_SetAttrString(result, "msg", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_msg, value) == -1) goto failed; Py_DECREF(value); break; @@ -2536,7 +2537,7 @@ ast2obj_stmt(void* _o) if (!result) goto failed; value = ast2obj_list(o->v.Import.names, ast2obj_alias); if (!value) goto failed; - if (PyObject_SetAttrString(result, "names", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) goto failed; Py_DECREF(value); break; @@ -2545,17 +2546,17 @@ ast2obj_stmt(void* _o) if (!result) goto failed; value = ast2obj_identifier(o->v.ImportFrom.module); if (!value) goto failed; - if (PyObject_SetAttrString(result, "module", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_module, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); if (!value) goto failed; - if (PyObject_SetAttrString(result, "names", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_int(o->v.ImportFrom.level); if (!value) goto failed; - if (PyObject_SetAttrString(result, "level", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_level, value) == -1) goto failed; Py_DECREF(value); break; @@ -2564,7 +2565,7 @@ ast2obj_stmt(void* _o) if (!result) goto failed; value = ast2obj_list(o->v.Global.names, ast2obj_identifier); if (!value) goto failed; - if (PyObject_SetAttrString(result, "names", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) goto failed; Py_DECREF(value); break; @@ -2573,7 +2574,7 @@ ast2obj_stmt(void* _o) if (!result) goto failed; value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); if (!value) goto failed; - if (PyObject_SetAttrString(result, "names", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) goto failed; Py_DECREF(value); break; @@ -2582,7 +2583,7 @@ ast2obj_stmt(void* _o) if (!result) goto failed; value = ast2obj_expr(o->v.Expr.value); if (!value) goto failed; - if (PyObject_SetAttrString(result, "value", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) goto failed; Py_DECREF(value); break; @@ -2601,12 +2602,12 @@ ast2obj_stmt(void* _o) } value = ast2obj_int(o->lineno); if (!value) goto failed; - if (PyObject_SetAttrString(result, "lineno", value) < 0) + if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) goto failed; Py_DECREF(value); value = ast2obj_int(o->col_offset); if (!value) goto failed; - if (PyObject_SetAttrString(result, "col_offset", value) < 0) + if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) goto failed; Py_DECREF(value); return result; @@ -2632,12 +2633,12 @@ ast2obj_expr(void* _o) if (!result) goto failed; value = ast2obj_boolop(o->v.BoolOp.op); if (!value) goto failed; - if (PyObject_SetAttrString(result, "op", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttrString(result, "values", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) goto failed; Py_DECREF(value); break; @@ -2646,17 +2647,17 @@ ast2obj_expr(void* _o) if (!result) goto failed; value = ast2obj_expr(o->v.BinOp.left); if (!value) goto failed; - if (PyObject_SetAttrString(result, "left", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_operator(o->v.BinOp.op); if (!value) goto failed; - if (PyObject_SetAttrString(result, "op", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.BinOp.right); if (!value) goto failed; - if (PyObject_SetAttrString(result, "right", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_right, value) == -1) goto failed; Py_DECREF(value); break; @@ -2665,12 +2666,12 @@ ast2obj_expr(void* _o) if (!result) goto failed; value = ast2obj_unaryop(o->v.UnaryOp.op); if (!value) goto failed; - if (PyObject_SetAttrString(result, "op", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.UnaryOp.operand); if (!value) goto failed; - if (PyObject_SetAttrString(result, "operand", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_operand, value) == -1) goto failed; Py_DECREF(value); break; @@ -2679,12 +2680,12 @@ ast2obj_expr(void* _o) if (!result) goto failed; value = ast2obj_arguments(o->v.Lambda.args); if (!value) goto failed; - if (PyObject_SetAttrString(result, "args", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.Lambda.body); if (!value) goto failed; - if (PyObject_SetAttrString(result, "body", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) goto failed; Py_DECREF(value); break; @@ -2693,17 +2694,17 @@ ast2obj_expr(void* _o) if (!result) goto failed; value = ast2obj_expr(o->v.IfExp.test); if (!value) goto failed; - if (PyObject_SetAttrString(result, "test", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.IfExp.body); if (!value) goto failed; - if (PyObject_SetAttrString(result, "body", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.IfExp.orelse); if (!value) goto failed; - if (PyObject_SetAttrString(result, "orelse", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) goto failed; Py_DECREF(value); break; @@ -2712,12 +2713,12 @@ ast2obj_expr(void* _o) if (!result) goto failed; value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttrString(result, "keys", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_keys, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.Dict.values, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttrString(result, "values", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) goto failed; Py_DECREF(value); break; @@ -2726,7 +2727,7 @@ ast2obj_expr(void* _o) if (!result) goto failed; value = ast2obj_list(o->v.Set.elts, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttrString(result, "elts", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) goto failed; Py_DECREF(value); break; @@ -2735,13 +2736,13 @@ ast2obj_expr(void* _o) if (!result) goto failed; value = ast2obj_expr(o->v.ListComp.elt); if (!value) goto failed; - if (PyObject_SetAttrString(result, "elt", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); if (!value) goto failed; - if (PyObject_SetAttrString(result, "generators", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) goto failed; Py_DECREF(value); break; @@ -2750,13 +2751,13 @@ ast2obj_expr(void* _o) if (!result) goto failed; value = ast2obj_expr(o->v.SetComp.elt); if (!value) goto failed; - if (PyObject_SetAttrString(result, "elt", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); if (!value) goto failed; - if (PyObject_SetAttrString(result, "generators", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) goto failed; Py_DECREF(value); break; @@ -2765,18 +2766,18 @@ ast2obj_expr(void* _o) if (!result) goto failed; value = ast2obj_expr(o->v.DictComp.key); if (!value) goto failed; - if (PyObject_SetAttrString(result, "key", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_key, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.DictComp.value); if (!value) goto failed; - if (PyObject_SetAttrString(result, "value", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension); if (!value) goto failed; - if (PyObject_SetAttrString(result, "generators", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) goto failed; Py_DECREF(value); break; @@ -2785,13 +2786,13 @@ ast2obj_expr(void* _o) if (!result) goto failed; value = ast2obj_expr(o->v.GeneratorExp.elt); if (!value) goto failed; - if (PyObject_SetAttrString(result, "elt", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.GeneratorExp.generators, ast2obj_comprehension); if (!value) goto failed; - if (PyObject_SetAttrString(result, "generators", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) goto failed; Py_DECREF(value); break; @@ -2800,7 +2801,7 @@ ast2obj_expr(void* _o) if (!result) goto failed; value = ast2obj_expr(o->v.Yield.value); if (!value) goto failed; - if (PyObject_SetAttrString(result, "value", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) goto failed; Py_DECREF(value); break; @@ -2809,7 +2810,7 @@ ast2obj_expr(void* _o) if (!result) goto failed; value = ast2obj_expr(o->v.Compare.left); if (!value) goto failed; - if (PyObject_SetAttrString(result, "left", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) goto failed; Py_DECREF(value); { @@ -2820,12 +2821,12 @@ ast2obj_expr(void* _o) PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i))); } if (!value) goto failed; - if (PyObject_SetAttrString(result, "ops", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_ops, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttrString(result, "comparators", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_comparators, value) == -1) goto failed; Py_DECREF(value); break; @@ -2834,27 +2835,27 @@ ast2obj_expr(void* _o) if (!result) goto failed; value = ast2obj_expr(o->v.Call.func); if (!value) goto failed; - if (PyObject_SetAttrString(result, "func", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_func, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.Call.args, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttrString(result, "args", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); if (!value) goto failed; - if (PyObject_SetAttrString(result, "keywords", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.Call.starargs); if (!value) goto failed; - if (PyObject_SetAttrString(result, "starargs", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_starargs, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.Call.kwargs); if (!value) goto failed; - if (PyObject_SetAttrString(result, "kwargs", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_kwargs, value) == -1) goto failed; Py_DECREF(value); break; @@ -2863,7 +2864,7 @@ ast2obj_expr(void* _o) if (!result) goto failed; value = ast2obj_object(o->v.Num.n); if (!value) goto failed; - if (PyObject_SetAttrString(result, "n", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_n, value) == -1) goto failed; Py_DECREF(value); break; @@ -2872,7 +2873,7 @@ ast2obj_expr(void* _o) if (!result) goto failed; value = ast2obj_string(o->v.Str.s); if (!value) goto failed; - if (PyObject_SetAttrString(result, "s", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) goto failed; Py_DECREF(value); break; @@ -2881,7 +2882,7 @@ ast2obj_expr(void* _o) if (!result) goto failed; value = ast2obj_bytes(o->v.Bytes.s); if (!value) goto failed; - if (PyObject_SetAttrString(result, "s", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) goto failed; Py_DECREF(value); break; @@ -2894,17 +2895,17 @@ ast2obj_expr(void* _o) if (!result) goto failed; value = ast2obj_expr(o->v.Attribute.value); if (!value) goto failed; - if (PyObject_SetAttrString(result, "value", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_identifier(o->v.Attribute.attr); if (!value) goto failed; - if (PyObject_SetAttrString(result, "attr", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_attr, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr_context(o->v.Attribute.ctx); if (!value) goto failed; - if (PyObject_SetAttrString(result, "ctx", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) goto failed; Py_DECREF(value); break; @@ -2913,17 +2914,17 @@ ast2obj_expr(void* _o) if (!result) goto failed; value = ast2obj_expr(o->v.Subscript.value); if (!value) goto failed; - if (PyObject_SetAttrString(result, "value", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_slice(o->v.Subscript.slice); if (!value) goto failed; - if (PyObject_SetAttrString(result, "slice", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_slice, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr_context(o->v.Subscript.ctx); if (!value) goto failed; - if (PyObject_SetAttrString(result, "ctx", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) goto failed; Py_DECREF(value); break; @@ -2932,12 +2933,12 @@ ast2obj_expr(void* _o) if (!result) goto failed; value = ast2obj_expr(o->v.Starred.value); if (!value) goto failed; - if (PyObject_SetAttrString(result, "value", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr_context(o->v.Starred.ctx); if (!value) goto failed; - if (PyObject_SetAttrString(result, "ctx", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) goto failed; Py_DECREF(value); break; @@ -2946,12 +2947,12 @@ ast2obj_expr(void* _o) if (!result) goto failed; value = ast2obj_identifier(o->v.Name.id); if (!value) goto failed; - if (PyObject_SetAttrString(result, "id", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_id, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr_context(o->v.Name.ctx); if (!value) goto failed; - if (PyObject_SetAttrString(result, "ctx", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) goto failed; Py_DECREF(value); break; @@ -2960,12 +2961,12 @@ ast2obj_expr(void* _o) if (!result) goto failed; value = ast2obj_list(o->v.List.elts, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttrString(result, "elts", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr_context(o->v.List.ctx); if (!value) goto failed; - if (PyObject_SetAttrString(result, "ctx", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) goto failed; Py_DECREF(value); break; @@ -2974,24 +2975,24 @@ ast2obj_expr(void* _o) if (!result) goto failed; value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttrString(result, "elts", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr_context(o->v.Tuple.ctx); if (!value) goto failed; - if (PyObject_SetAttrString(result, "ctx", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) goto failed; Py_DECREF(value); break; } value = ast2obj_int(o->lineno); if (!value) goto failed; - if (PyObject_SetAttrString(result, "lineno", value) < 0) + if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) goto failed; Py_DECREF(value); value = ast2obj_int(o->col_offset); if (!value) goto failed; - if (PyObject_SetAttrString(result, "col_offset", value) < 0) + if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) goto failed; Py_DECREF(value); return result; @@ -3044,17 +3045,17 @@ ast2obj_slice(void* _o) if (!result) goto failed; value = ast2obj_expr(o->v.Slice.lower); if (!value) goto failed; - if (PyObject_SetAttrString(result, "lower", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_lower, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.Slice.upper); if (!value) goto failed; - if (PyObject_SetAttrString(result, "upper", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_upper, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.Slice.step); if (!value) goto failed; - if (PyObject_SetAttrString(result, "step", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_step, value) == -1) goto failed; Py_DECREF(value); break; @@ -3063,7 +3064,7 @@ ast2obj_slice(void* _o) if (!result) goto failed; value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); if (!value) goto failed; - if (PyObject_SetAttrString(result, "dims", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_dims, value) == -1) goto failed; Py_DECREF(value); break; @@ -3072,7 +3073,7 @@ ast2obj_slice(void* _o) if (!result) goto failed; value = ast2obj_expr(o->v.Index.value); if (!value) goto failed; - if (PyObject_SetAttrString(result, "value", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) goto failed; Py_DECREF(value); break; @@ -3218,17 +3219,17 @@ ast2obj_comprehension(void* _o) if (!result) return NULL; value = ast2obj_expr(o->target); if (!value) goto failed; - if (PyObject_SetAttrString(result, "target", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->iter); if (!value) goto failed; - if (PyObject_SetAttrString(result, "iter", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->ifs, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttrString(result, "ifs", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_ifs, value) == -1) goto failed; Py_DECREF(value); return result; @@ -3254,29 +3255,29 @@ ast2obj_excepthandler(void* _o) if (!result) goto failed; value = ast2obj_expr(o->v.ExceptHandler.type); if (!value) goto failed; - if (PyObject_SetAttrString(result, "type", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_type, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_identifier(o->v.ExceptHandler.name); if (!value) goto failed; - if (PyObject_SetAttrString(result, "name", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); if (!value) goto failed; - if (PyObject_SetAttrString(result, "body", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) goto failed; Py_DECREF(value); break; } value = ast2obj_int(o->lineno); if (!value) goto failed; - if (PyObject_SetAttrString(result, "lineno", value) < 0) + if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) goto failed; Py_DECREF(value); value = ast2obj_int(o->col_offset); if (!value) goto failed; - if (PyObject_SetAttrString(result, "col_offset", value) < 0) + if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) goto failed; Py_DECREF(value); return result; @@ -3300,42 +3301,42 @@ ast2obj_arguments(void* _o) if (!result) return NULL; value = ast2obj_list(o->args, ast2obj_arg); if (!value) goto failed; - if (PyObject_SetAttrString(result, "args", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_identifier(o->vararg); if (!value) goto failed; - if (PyObject_SetAttrString(result, "vararg", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_vararg, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->varargannotation); if (!value) goto failed; - if (PyObject_SetAttrString(result, "varargannotation", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_varargannotation, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->kwonlyargs, ast2obj_arg); if (!value) goto failed; - if (PyObject_SetAttrString(result, "kwonlyargs", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_kwonlyargs, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_identifier(o->kwarg); if (!value) goto failed; - if (PyObject_SetAttrString(result, "kwarg", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->kwargannotation); if (!value) goto failed; - if (PyObject_SetAttrString(result, "kwargannotation", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_kwargannotation, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->defaults, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttrString(result, "defaults", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_list(o->kw_defaults, ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttrString(result, "kw_defaults", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1) goto failed; Py_DECREF(value); return result; @@ -3359,12 +3360,12 @@ ast2obj_arg(void* _o) if (!result) return NULL; value = ast2obj_identifier(o->arg); if (!value) goto failed; - if (PyObject_SetAttrString(result, "arg", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->annotation); if (!value) goto failed; - if (PyObject_SetAttrString(result, "annotation", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) goto failed; Py_DECREF(value); return result; @@ -3388,12 +3389,12 @@ ast2obj_keyword(void* _o) if (!result) return NULL; value = ast2obj_identifier(o->arg); if (!value) goto failed; - if (PyObject_SetAttrString(result, "arg", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->value); if (!value) goto failed; - if (PyObject_SetAttrString(result, "value", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) goto failed; Py_DECREF(value); return result; @@ -3417,12 +3418,12 @@ ast2obj_alias(void* _o) if (!result) return NULL; value = ast2obj_identifier(o->name); if (!value) goto failed; - if (PyObject_SetAttrString(result, "name", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_identifier(o->asname); if (!value) goto failed; - if (PyObject_SetAttrString(result, "asname", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_asname, value) == -1) goto failed; Py_DECREF(value); return result; @@ -3446,12 +3447,12 @@ ast2obj_withitem(void* _o) if (!result) return NULL; value = ast2obj_expr(o->context_expr); if (!value) goto failed; - if (PyObject_SetAttrString(result, "context_expr", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_context_expr, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->optional_vars); if (!value) goto failed; - if (PyObject_SetAttrString(result, "optional_vars", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_optional_vars, value) == -1) goto failed; Py_DECREF(value); return result; -- cgit v1.2.1 From e4f5fc423651e760f014159dce83273f9d54831c Mon Sep 17 00:00:00 2001 From: Nick Coghlan Date: Fri, 13 Jan 2012 21:43:40 +1000 Subject: Implement PEP 380 - 'yield from' (closes #11682) --- Python/Python-ast.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 8a101cf3b0..3121eb1bb7 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -231,7 +231,9 @@ static char *GeneratorExp_fields[]={ "generators", }; static PyTypeObject *Yield_type; +_Py_IDENTIFIER(is_from); static char *Yield_fields[]={ + "is_from", "value", }; static PyTypeObject *Compare_type; @@ -810,7 +812,7 @@ static int init_types(void) GeneratorExp_type = make_type("GeneratorExp", expr_type, GeneratorExp_fields, 2); if (!GeneratorExp_type) return 0; - Yield_type = make_type("Yield", expr_type, Yield_fields, 1); + Yield_type = make_type("Yield", expr_type, Yield_fields, 2); if (!Yield_type) return 0; Compare_type = make_type("Compare", expr_type, Compare_fields, 3); if (!Compare_type) return 0; @@ -1747,13 +1749,14 @@ GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, } expr_ty -Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) +Yield(int is_from, expr_ty value, int lineno, int col_offset, PyArena *arena) { expr_ty p; p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); if (!p) return NULL; p->kind = Yield_kind; + p->v.Yield.is_from = is_from; p->v.Yield.value = value; p->lineno = lineno; p->col_offset = col_offset; @@ -2795,6 +2798,11 @@ ast2obj_expr(void* _o) case Yield_kind: result = PyType_GenericNew(Yield_type, NULL, NULL); if (!result) goto failed; + value = ast2obj_int(o->v.Yield.is_from); + if (!value) goto failed; + if (PyObject_SetAttrString(result, "is_from", value) == -1) + goto failed; + Py_DECREF(value); value = ast2obj_expr(o->v.Yield.value); if (!value) goto failed; if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) @@ -5337,8 +5345,21 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) return 1; } if (isinstance) { + int is_from; expr_ty value; + if (_PyObject_HasAttrId(obj, &PyId_is_from)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_is_from); + if (tmp == NULL) goto failed; + res = obj2ast_int(tmp, &is_from, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"is_from\" missing from Yield"); + return 1; + } if (_PyObject_HasAttrId(obj, &PyId_value)) { int res; tmp = _PyObject_GetAttrId(obj, &PyId_value); @@ -5350,7 +5371,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { value = NULL; } - *out = Yield(value, lineno, col_offset, arena); + *out = Yield(is_from, value, lineno, col_offset, arena); if (*out == NULL) goto failed; return 0; } -- cgit v1.2.1 From 1434e995657f5525a55584535d023dbe0ce2af24 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Fri, 13 Jan 2012 18:52:16 +0100 Subject: Issue #13645: pyc files now contain the size of the corresponding source code, to avoid timestamp collisions (especially on filesystems with a low timestamp resolution) when checking for freshness of the bytecode. --- Python/Python-ast.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 3121eb1bb7..2882bbc073 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -2800,7 +2800,7 @@ ast2obj_expr(void* _o) if (!result) goto failed; value = ast2obj_int(o->v.Yield.is_from); if (!value) goto failed; - if (PyObject_SetAttrString(result, "is_from", value) == -1) + if (_PyObject_SetAttrId(result, &PyId_is_from, value) == -1) goto failed; Py_DECREF(value); value = ast2obj_expr(o->v.Yield.value); -- cgit v1.2.1 From 37fe2bd5e9be127591b1e39efe50fc0c3348b5ab Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sat, 14 Jan 2012 08:58:23 -0500 Subject: make YieldFrom its own distinct from Yield (closes #13780) --- Python/Python-ast.c | 62 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 15 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 2882bbc073..2603b812f0 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -231,9 +231,11 @@ static char *GeneratorExp_fields[]={ "generators", }; static PyTypeObject *Yield_type; -_Py_IDENTIFIER(is_from); static char *Yield_fields[]={ - "is_from", + "value", +}; +static PyTypeObject *YieldFrom_type; +static char *YieldFrom_fields[]={ "value", }; static PyTypeObject *Compare_type; @@ -812,8 +814,10 @@ static int init_types(void) GeneratorExp_type = make_type("GeneratorExp", expr_type, GeneratorExp_fields, 2); if (!GeneratorExp_type) return 0; - Yield_type = make_type("Yield", expr_type, Yield_fields, 2); + Yield_type = make_type("Yield", expr_type, Yield_fields, 1); if (!Yield_type) return 0; + YieldFrom_type = make_type("YieldFrom", expr_type, YieldFrom_fields, 1); + if (!YieldFrom_type) return 0; Compare_type = make_type("Compare", expr_type, Compare_fields, 3); if (!Compare_type) return 0; Call_type = make_type("Call", expr_type, Call_fields, 5); @@ -1749,20 +1753,33 @@ GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, } expr_ty -Yield(int is_from, expr_ty value, int lineno, int col_offset, PyArena *arena) +Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) { expr_ty p; p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); if (!p) return NULL; p->kind = Yield_kind; - p->v.Yield.is_from = is_from; p->v.Yield.value = value; p->lineno = lineno; p->col_offset = col_offset; return p; } +expr_ty +YieldFrom(expr_ty value, int lineno, int col_offset, PyArena *arena) +{ + expr_ty p; + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = YieldFrom_kind; + p->v.YieldFrom.value = value; + p->lineno = lineno; + p->col_offset = col_offset; + return p; +} + expr_ty Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, int col_offset, PyArena *arena) @@ -2798,12 +2815,16 @@ ast2obj_expr(void* _o) case Yield_kind: result = PyType_GenericNew(Yield_type, NULL, NULL); if (!result) goto failed; - value = ast2obj_int(o->v.Yield.is_from); + value = ast2obj_expr(o->v.Yield.value); if (!value) goto failed; - if (_PyObject_SetAttrId(result, &PyId_is_from, value) == -1) + if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_expr(o->v.Yield.value); + break; + case YieldFrom_kind: + result = PyType_GenericNew(YieldFrom_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_expr(o->v.YieldFrom.value); if (!value) goto failed; if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) goto failed; @@ -5345,21 +5366,30 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) return 1; } if (isinstance) { - int is_from; expr_ty value; - if (_PyObject_HasAttrId(obj, &PyId_is_from)) { + if (_PyObject_HasAttrId(obj, &PyId_value)) { int res; - tmp = _PyObject_GetAttrId(obj, &PyId_is_from); + tmp = _PyObject_GetAttrId(obj, &PyId_value); if (tmp == NULL) goto failed; - res = obj2ast_int(tmp, &is_from, arena); + res = obj2ast_expr(tmp, &value, arena); if (res != 0) goto failed; Py_XDECREF(tmp); tmp = NULL; } else { - PyErr_SetString(PyExc_TypeError, "required field \"is_from\" missing from Yield"); - return 1; + value = NULL; } + *out = Yield(value, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } + isinstance = PyObject_IsInstance(obj, (PyObject*)YieldFrom_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + expr_ty value; + if (_PyObject_HasAttrId(obj, &PyId_value)) { int res; tmp = _PyObject_GetAttrId(obj, &PyId_value); @@ -5371,7 +5401,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) } else { value = NULL; } - *out = Yield(is_from, value, lineno, col_offset, arena); + *out = YieldFrom(value, lineno, col_offset, arena); if (*out == NULL) goto failed; return 0; } @@ -6928,6 +6958,8 @@ PyInit__ast(void) (PyObject*)GeneratorExp_type) < 0) return NULL; if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return NULL; + if (PyDict_SetItemString(d, "YieldFrom", (PyObject*)YieldFrom_type) < + 0) return NULL; if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) return NULL; if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return -- cgit v1.2.1 From 9e7326a599e76cc4f5bd03e6b3744d4008a01ade Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Mon, 12 Mar 2012 09:46:44 -0700 Subject: give the AST class a __dict__ --- Python/Python-ast.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 2603b812f0..cf73beaa15 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -1,5 +1,7 @@ /* File automatically generated by Parser/asdl_c.py. */ +#include + #include "Python.h" #include "Python-ast.h" @@ -453,6 +455,11 @@ static char *withitem_fields[]={ }; +typedef struct { + PyObject_HEAD; + PyObject *dict; +} AST_object; + static int ast_type_init(PyObject *self, PyObject *args, PyObject *kw) { @@ -531,10 +538,15 @@ static PyMethodDef ast_type_methods[] = { {NULL} }; +static PyGetSetDef ast_type_getsets[] = { + {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, + {NULL} +}; + static PyTypeObject AST_type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "_ast.AST", - sizeof(PyObject), + sizeof(AST_object), 0, 0, /* tp_dealloc */ 0, /* tp_print */ @@ -561,12 +573,12 @@ static PyTypeObject AST_type = { 0, /* tp_iternext */ ast_type_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ + ast_type_getsets, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ + offsetof(AST_object, dict),/* tp_dictoffset */ (initproc)ast_type_init, /* tp_init */ PyType_GenericAlloc, /* tp_alloc */ PyType_GenericNew, /* tp_new */ -- cgit v1.2.1 From d5bb8362e9a919dab6fd05eba0731a3db3a5063f Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 13 Mar 2012 01:17:31 +0100 Subject: Try to fix compilation of Python-ast.c on Visual Studio 2008 --- Python/Python-ast.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index cf73beaa15..1178d74d7f 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -456,7 +456,7 @@ static char *withitem_fields[]={ typedef struct { - PyObject_HEAD; + PyObject_HEAD PyObject *dict; } AST_object; -- cgit v1.2.1 From feb250da193d7840bcf341f8e1630dd70afde01d Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Wed, 14 Mar 2012 21:50:29 -0500 Subject: free AST's dict --- Python/Python-ast.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 1178d74d7f..d9e13e28b0 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -460,6 +460,12 @@ typedef struct { PyObject *dict; } AST_object; +static void +ast_dealloc(AST_object *self) +{ + Py_CLEAR(self->dict); +} + static int ast_type_init(PyObject *self, PyObject *args, PyObject *kw) { @@ -548,7 +554,7 @@ static PyTypeObject AST_type = { "_ast.AST", sizeof(AST_object), 0, - 0, /* tp_dealloc */ + (destructor)ast_dealloc, /* tp_dealloc */ 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ -- cgit v1.2.1 From 6c56fb87a67308d5d9530ae892d8d5f230549c64 Mon Sep 17 00:00:00 2001 From: "Martin v. L?wis" Date: Tue, 15 May 2012 14:45:03 +0200 Subject: Widen ASDL sequences to Py_ssize_t lengths to better match PEP 353. --- Python/Python-ast.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index d9e13e28b0..4ca269f9f5 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -636,7 +636,7 @@ static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) { - int i, n = asdl_seq_LEN(seq); + Py_ssize_t i, n = asdl_seq_LEN(seq); PyObject *result = PyList_New(n); PyObject *value; if (!result) @@ -2857,7 +2857,7 @@ ast2obj_expr(void* _o) goto failed; Py_DECREF(value); { - int i, n = asdl_seq_LEN(o->v.Compare.ops); + Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); value = PyList_New(n); if (!value) goto failed; for(i = 0; i < n; i++) -- cgit v1.2.1 From fc75063925b1cf344e214177a3ddfd7ac3d961ca Mon Sep 17 00:00:00 2001 From: "Martin v. L?wis" Date: Tue, 15 May 2012 14:52:36 +0200 Subject: Document f4d7ad6c9d6e. --- Python/Python-ast.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 4ca269f9f5..d9e13e28b0 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -636,7 +636,7 @@ static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) { - Py_ssize_t i, n = asdl_seq_LEN(seq); + int i, n = asdl_seq_LEN(seq); PyObject *result = PyList_New(n); PyObject *value; if (!result) @@ -2857,7 +2857,7 @@ ast2obj_expr(void* _o) goto failed; Py_DECREF(value); { - Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); + int i, n = asdl_seq_LEN(o->v.Compare.ops); value = PyList_New(n); if (!value) goto failed; for(i = 0; i < n; i++) -- cgit v1.2.1 From fa58516f67e4c7f9d23658c6a46cf2e64f8d6290 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Tue, 15 May 2012 10:10:27 -0700 Subject: use Py_ssize_t for ast sequence lengths --- Python/Python-ast.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index d9e13e28b0..4ca269f9f5 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -636,7 +636,7 @@ static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) { - int i, n = asdl_seq_LEN(seq); + Py_ssize_t i, n = asdl_seq_LEN(seq); PyObject *result = PyList_New(n); PyObject *value; if (!result) @@ -2857,7 +2857,7 @@ ast2obj_expr(void* _o) goto failed; Py_DECREF(value); { - int i, n = asdl_seq_LEN(o->v.Compare.ops); + Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); value = PyList_New(n); if (!value) goto failed; for(i = 0; i < n; i++) -- cgit v1.2.1 From 2b67f44a26493fb494b862b2c88681e2e0db4f88 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sun, 8 Jul 2012 12:43:32 +0200 Subject: Issue #15291: Fix a memory leak where AST nodes where not properly deallocated. --- Python/Python-ast.c | 1 + 1 file changed, 1 insertion(+) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 4ca269f9f5..60147fa15b 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -464,6 +464,7 @@ static void ast_dealloc(AST_object *self) { Py_CLEAR(self->dict); + Py_TYPE(self)->tp_free(self); } static int -- cgit v1.2.1 From a12f419e5ae84cc76f2cae4b598f3d77e01737a0 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sun, 8 Jul 2012 11:03:46 -0700 Subject: add gc support to the AST base type (closes #15293) --- Python/Python-ast.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 60147fa15b..805f2b8af1 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -467,6 +467,19 @@ ast_dealloc(AST_object *self) Py_TYPE(self)->tp_free(self); } +static int +ast_traverse(AST_object *self, visitproc visit, void *arg) +{ + Py_VISIT(self->dict); + return 0; +} + +static void +ast_clear(AST_object *self) +{ + Py_CLEAR(self->dict); +} + static int ast_type_init(PyObject *self, PyObject *args, PyObject *kw) { @@ -570,10 +583,10 @@ static PyTypeObject AST_type = { PyObject_GenericGetAttr, /* tp_getattro */ PyObject_GenericSetAttr, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ 0, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ + (traverseproc)ast_traverse, /* tp_traverse */ + (inquiry)ast_clear, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ @@ -589,7 +602,7 @@ static PyTypeObject AST_type = { (initproc)ast_type_init, /* tp_init */ PyType_GenericAlloc, /* tp_alloc */ PyType_GenericNew, /* tp_new */ - PyObject_Del, /* tp_free */ + PyObject_GC_Del, /* tp_free */ }; -- cgit v1.2.1 From 5cd62b7fe17e8004a4f137cf9164e4e71bb1bd70 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Sun, 25 Nov 2012 14:36:26 +0000 Subject: Issue #16546: make ast.YieldFrom argument mandatory. --- Python/Python-ast.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'Python/Python-ast.c') diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 805f2b8af1..e6f1e58252 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -1802,6 +1802,11 @@ expr_ty YieldFrom(expr_ty value, int lineno, int col_offset, PyArena *arena) { expr_ty p; + if (!value) { + PyErr_SetString(PyExc_ValueError, + "field value is required for YieldFrom"); + return NULL; + } p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); if (!p) return NULL; @@ -5431,7 +5436,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_XDECREF(tmp); tmp = NULL; } else { - value = NULL; + PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); + return 1; } *out = YieldFrom(value, lineno, col_offset, arena); if (*out == NULL) goto failed; -- cgit v1.2.1