summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Modules/_cursesmodule.c11
-rw-r--r--Modules/_pickle.c7
-rw-r--r--Modules/itertoolsmodule.c4
-rw-r--r--Objects/descrobject.c2
-rw-r--r--Objects/dictobject.c5
-rwxr-xr-xParser/asdl_c.py7
-rw-r--r--Python/Python-ast.c269
-rw-r--r--Python/_warnings.c32
-rw-r--r--Python/ceval.c6
-rw-r--r--Python/errors.c26
-rw-r--r--Python/pythonrun.c9
-rw-r--r--Python/sysmodule.c5
12 files changed, 200 insertions, 183 deletions
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
index dddaa3a..8790243 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -2454,6 +2454,8 @@ update_lines_cols(void)
{
PyObject *o;
PyObject *m = PyImport_ImportModuleNoBlock("curses");
+ _Py_IDENTIFIER(LINES);
+ _Py_IDENTIFIER(COLS);
if (!m)
return 0;
@@ -2463,12 +2465,13 @@ update_lines_cols(void)
Py_DECREF(m);
return 0;
}
- if (PyObject_SetAttrString(m, "LINES", o)) {
+ if (_PyObject_SetAttrId(m, &PyId_LINES, o)) {
Py_DECREF(m);
Py_DECREF(o);
return 0;
}
- if (PyDict_SetItemString(ModDict, "LINES", o)) {
+ /* PyId_LINES.object will be initialized here. */
+ if (PyDict_SetItem(ModDict, PyId_LINES.object, o)) {
Py_DECREF(m);
Py_DECREF(o);
return 0;
@@ -2479,12 +2482,12 @@ update_lines_cols(void)
Py_DECREF(m);
return 0;
}
- if (PyObject_SetAttrString(m, "COLS", o)) {
+ if (_PyObject_SetAttrId(m, &PyId_COLS, o)) {
Py_DECREF(m);
Py_DECREF(o);
return 0;
}
- if (PyDict_SetItemString(ModDict, "COLS", o)) {
+ if (PyDict_SetItem(ModDict, PyId_COLS.object, o)) {
Py_DECREF(m);
Py_DECREF(o);
return 0;
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index 2c29b20..f1bb730 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -4388,12 +4388,13 @@ static PyObject *
instantiate(PyObject *cls, PyObject *args)
{
PyObject *result = NULL;
+ _Py_IDENTIFIER(__getinitargs__);
/* Caller must assure args are a tuple. Normally, args come from
Pdata_poptuple which packs objects from the top of the stack
into a newly created tuple. */
assert(PyTuple_Check(args));
if (Py_SIZE(args) > 0 || !PyType_Check(cls) ||
- PyObject_HasAttrString(cls, "__getinitargs__")) {
+ _PyObject_HasAttrId(cls, &PyId___getinitargs__)) {
result = PyObject_CallObject(cls, args);
}
else {
@@ -5557,6 +5558,7 @@ Unpickler_init(UnpicklerObject *self, PyObject *args, PyObject *kwds)
PyObject *fix_imports = Py_True;
char *encoding = NULL;
char *errors = NULL;
+ _Py_IDENTIFIER(persistent_load);
/* XXX: That is an horrible error message. But, I don't know how to do
better... */
@@ -5591,8 +5593,7 @@ Unpickler_init(UnpicklerObject *self, PyObject *args, PyObject *kwds)
if (self->fix_imports == -1)
return -1;
- if (PyObject_HasAttrString((PyObject *)self, "persistent_load")) {
- _Py_IDENTIFIER(persistent_load);
+ if (_PyObject_HasAttrId((PyObject *)self, &PyId_persistent_load)) {
self->pers_func = _PyObject_GetAttrId((PyObject *)self,
&PyId_persistent_load);
if (self->pers_func == NULL)
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 63f199b..15b0c17 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -626,6 +626,7 @@ tee(PyObject *self, PyObject *args)
{
Py_ssize_t i, n=2;
PyObject *it, *iterable, *copyable, *result;
+ _Py_IDENTIFIER(__copy__);
if (!PyArg_ParseTuple(args, "O|n", &iterable, &n))
return NULL;
@@ -643,7 +644,7 @@ tee(PyObject *self, PyObject *args)
Py_DECREF(result);
return NULL;
}
- if (!PyObject_HasAttrString(it, "__copy__")) {
+ if (!_PyObject_HasAttrId(it, &PyId___copy__)) {
copyable = tee_fromiterable(it);
Py_DECREF(it);
if (copyable == NULL) {
@@ -654,7 +655,6 @@ tee(PyObject *self, PyObject *args)
copyable = it;
PyTuple_SET_ITEM(result, 0, copyable);
for (i=1 ; i<n ; i++) {
- _Py_IDENTIFIER(__copy__);
copyable = _PyObject_CallMethodId(copyable, &PyId___copy__, NULL);
if (copyable == NULL) {
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
index 6e2d34e..b328a45 100644
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -1311,7 +1311,7 @@ property_init(PyObject *self, PyObject *args, PyObject *kwds)
in dict of the subclass instance instead,
otherwise it gets shadowed by __doc__ in the
class's dict. */
- int err = PyObject_SetAttrString(self, "__doc__", get_doc);
+ int err = _PyObject_SetAttrId(self, &PyId___doc__, get_doc);
Py_DECREF(get_doc);
if (err < 0)
return -1;
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 3896b31..865feff 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -1387,7 +1387,8 @@ dict_update_common(PyObject *self, PyObject *args, PyObject *kwds, char *methnam
result = -1;
else if (arg != NULL) {
- if (PyObject_HasAttrString(arg, "keys"))
+ _Py_IDENTIFIER(keys);
+ if (_PyObject_HasAttrId(arg, &PyId_keys))
result = PyDict_Merge(self, arg, 1);
else
result = PyDict_MergeFromSeq2(self, arg, 1);
@@ -2747,7 +2748,7 @@ dictviews_or(PyObject* self, PyObject *other)
{
PyObject *result = PySet_New(self);
PyObject *tmp;
- _Py_identifier(update);
+ _Py_IDENTIFIER(update);
if (result == NULL)
return NULL;
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
index 5501ebc..deff06d 100755
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -747,6 +747,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;
@@ -758,7 +759,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;
}
@@ -1024,7 +1025,7 @@ class ObjVisitor(PickleVisitor):
for a in sum.attributes:
self.emit("value = ast2obj_%s(o->%s);" % (a.type, a.name), 1)
self.emit("if (!value) goto failed;", 1)
- self.emit('if (PyObject_SetAttrString(result, "%s", value) < 0)' % a.name, 1)
+ self.emit('if (_PyObject_SetAttrId(result, &PyId_%s, value) < 0)' % a.name, 1)
self.emit('goto failed;', 2)
self.emit('Py_DECREF(value);', 1)
self.func_end()
@@ -1070,7 +1071,7 @@ class ObjVisitor(PickleVisitor):
value = "o->v.%s.%s" % (name, field.name)
self.set(field, value, depth)
emit("if (!value) goto failed;", 0)
- emit('if (PyObject_SetAttrString(result, "%s", value) == -1)' % field.name, 0)
+ emit('if (_PyObject_SetAttrId(result, &PyId_%s, value) == -1)' % field.name, 0)
emit("goto failed;", 1)
emit("Py_DECREF(value);", 0)
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index 7c0d858..3cfb8a8 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;
diff --git a/Python/_warnings.c b/Python/_warnings.c
index 6fcc128..5846426 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -654,8 +654,9 @@ warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds)
return NULL;
if (module_globals) {
- static PyObject *get_source_name = NULL;
- static PyObject *splitlines_name = NULL;
+ _Py_IDENTIFIER(get_source);
+ _Py_IDENTIFIER(splitlines);
+ PyObject *tmp;
PyObject *loader;
PyObject *module_name;
PyObject *source;
@@ -663,16 +664,12 @@ warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds)
PyObject *source_line;
PyObject *returned;
- if (get_source_name == NULL) {
- get_source_name = PyUnicode_InternFromString("get_source");
- if (!get_source_name)
- return NULL;
- }
- if (splitlines_name == NULL) {
- splitlines_name = PyUnicode_InternFromString("splitlines");
- if (!splitlines_name)
- return NULL;
- }
+ if ((tmp = _PyUnicode_FromId(&PyId_get_source)) == NULL)
+ return NULL;
+ Py_DECREF(tmp);
+ if ((tmp = _PyUnicode_FromId(&PyId_splitlines)) == NULL)
+ return NULL;
+ Py_DECREF(tmp);
/* Check/get the requisite pieces needed for the loader. */
loader = PyDict_GetItemString(module_globals, "__loader__");
@@ -682,11 +679,11 @@ warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds)
goto standard_call;
/* Make sure the loader implements the optional get_source() method. */
- if (!PyObject_HasAttrString(loader, "get_source"))
+ if (!_PyObject_HasAttrId(loader, &PyId_get_source))
goto standard_call;
/* Call get_source() to get the source code. */
- source = PyObject_CallMethodObjArgs(loader, get_source_name,
- module_name, NULL);
+ source = PyObject_CallMethodObjArgs(loader, PyId_get_source.object,
+ module_name, NULL);
if (!source)
return NULL;
else if (source == Py_None) {
@@ -695,8 +692,9 @@ warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds)
}
/* Split the source into lines. */
- source_list = PyObject_CallMethodObjArgs(source, splitlines_name,
- NULL);
+ source_list = PyObject_CallMethodObjArgs(source,
+ PyId_splitlines.object,
+ NULL);
Py_DECREF(source);
if (!source_list)
return NULL;
diff --git a/Python/ceval.c b/Python/ceval.c
index 543c6f2..8d980fd 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4422,7 +4422,9 @@ import_from(PyObject *v, PyObject *name)
static int
import_all_from(PyObject *locals, PyObject *v)
{
- PyObject *all = PyObject_GetAttrString(v, "__all__");
+ _Py_IDENTIFIER(__all__);
+ _Py_IDENTIFIER(__dict__);
+ PyObject *all = _PyObject_GetAttrId(v, &PyId___all__);
PyObject *dict, *name, *value;
int skip_leading_underscores = 0;
int pos, err;
@@ -4431,7 +4433,7 @@ import_all_from(PyObject *locals, PyObject *v)
if (!PyErr_ExceptionMatches(PyExc_AttributeError))
return -1; /* Unexpected error */
PyErr_Clear();
- dict = PyObject_GetAttrString(v, "__dict__");
+ dict = _PyObject_GetAttrId(v, &PyId___dict__);
if (dict == NULL) {
if (!PyErr_ExceptionMatches(PyExc_AttributeError))
return -1;
diff --git a/Python/errors.c b/Python/errors.c
index 998bef6..d62648b 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -780,6 +780,12 @@ void
PyErr_SyntaxLocationEx(const char *filename, int lineno, int col_offset)
{
PyObject *exc, *v, *tb, *tmp;
+ _Py_IDENTIFIER(filename);
+ _Py_IDENTIFIER(lineno);
+ _Py_IDENTIFIER(msg);
+ _Py_IDENTIFIER(offset);
+ _Py_IDENTIFIER(print_file_and_line);
+ _Py_IDENTIFIER(text);
/* add attributes for the line number and filename for the error */
PyErr_Fetch(&exc, &v, &tb);
@@ -790,7 +796,7 @@ PyErr_SyntaxLocationEx(const char *filename, int lineno, int col_offset)
if (tmp == NULL)
PyErr_Clear();
else {
- if (PyObject_SetAttrString(v, "lineno", tmp))
+ if (_PyObject_SetAttrId(v, &PyId_lineno, tmp))
PyErr_Clear();
Py_DECREF(tmp);
}
@@ -799,7 +805,7 @@ PyErr_SyntaxLocationEx(const char *filename, int lineno, int col_offset)
if (tmp == NULL)
PyErr_Clear();
else {
- if (PyObject_SetAttrString(v, "offset", tmp))
+ if (_PyObject_SetAttrId(v, &PyId_offset, tmp))
PyErr_Clear();
Py_DECREF(tmp);
}
@@ -809,35 +815,35 @@ PyErr_SyntaxLocationEx(const char *filename, int lineno, int col_offset)
if (tmp == NULL)
PyErr_Clear();
else {
- if (PyObject_SetAttrString(v, "filename", tmp))
+ if (_PyObject_SetAttrId(v, &PyId_filename, tmp))
PyErr_Clear();
Py_DECREF(tmp);
}
tmp = PyErr_ProgramText(filename, lineno);
if (tmp) {
- if (PyObject_SetAttrString(v, "text", tmp))
+ if (_PyObject_SetAttrId(v, &PyId_text, tmp))
PyErr_Clear();
Py_DECREF(tmp);
}
}
- if (PyObject_SetAttrString(v, "offset", Py_None)) {
+ if (_PyObject_SetAttrId(v, &PyId_offset, Py_None)) {
PyErr_Clear();
}
if (exc != PyExc_SyntaxError) {
- if (!PyObject_HasAttrString(v, "msg")) {
+ if (!_PyObject_HasAttrId(v, &PyId_msg)) {
tmp = PyObject_Str(v);
if (tmp) {
- if (PyObject_SetAttrString(v, "msg", tmp))
+ if (_PyObject_SetAttrId(v, &PyId_msg, tmp))
PyErr_Clear();
Py_DECREF(tmp);
} else {
PyErr_Clear();
}
}
- if (!PyObject_HasAttrString(v, "print_file_and_line")) {
- if (PyObject_SetAttrString(v, "print_file_and_line",
- Py_None))
+ if (!_PyObject_HasAttrId(v, &PyId_print_file_and_line)) {
+ if (_PyObject_SetAttrId(v, &PyId_print_file_and_line,
+ Py_None))
PyErr_Clear();
}
}
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 0ce61a5..a6e7c46 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -810,6 +810,8 @@ create_stdio(PyObject* io,
_Py_IDENTIFIER(open);
_Py_IDENTIFIER(isatty);
_Py_IDENTIFIER(TextIOWrapper);
+ _Py_IDENTIFIER(name);
+ _Py_IDENTIFIER(mode);
/* stdin is always opened in buffered mode, first because it shouldn't
make a difference in common use cases, second because TextIOWrapper
@@ -842,7 +844,7 @@ create_stdio(PyObject* io,
}
text = PyUnicode_FromString(name);
- if (text == NULL || PyObject_SetAttrString(raw, "name", text) < 0)
+ if (text == NULL || _PyObject_SetAttrId(raw, &PyId_name, text) < 0)
goto error;
res = _PyObject_CallMethodId(raw, &PyId_isatty, "");
if (res == NULL)
@@ -879,7 +881,7 @@ create_stdio(PyObject* io,
else
mode = "r";
text = PyUnicode_FromString(mode);
- if (!text || PyObject_SetAttrString(stream, "mode", text) < 0)
+ if (!text || _PyObject_SetAttrId(stream, &PyId_mode, text) < 0)
goto error;
Py_CLEAR(text);
return stream;
@@ -1547,6 +1549,7 @@ print_exception(PyObject *f, PyObject *value)
{
int err = 0;
PyObject *type, *tb;
+ _Py_IDENTIFIER(print_file_and_line);
if (!PyExceptionInstance_Check(value)) {
PyFile_WriteString("TypeError: print_exception(): Exception expected for value, ", f);
@@ -1562,7 +1565,7 @@ print_exception(PyObject *f, PyObject *value)
if (tb && tb != Py_None)
err = PyTraceBack_Print(tb, f);
if (err == 0 &&
- PyObject_HasAttrString(value, "print_file_and_line"))
+ _PyObject_HasAttrId(value, &PyId_print_file_and_line))
{
PyObject *message;
const char *filename, *text;
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 7a1933d..6911c9a 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -139,6 +139,7 @@ sys_displayhook(PyObject *self, PyObject *o)
PyObject *modules = interp->modules;
PyObject *builtins = PyDict_GetItemString(modules, "builtins");
int err;
+ _Py_IDENTIFIER(_);
if (builtins == NULL) {
PyErr_SetString(PyExc_RuntimeError, "lost builtins module");
@@ -152,7 +153,7 @@ sys_displayhook(PyObject *self, PyObject *o)
Py_INCREF(Py_None);
return Py_None;
}
- if (PyObject_SetAttrString(builtins, "_", Py_None) != 0)
+ if (_PyObject_SetAttrId(builtins, &PyId__, Py_None) != 0)
return NULL;
outf = PySys_GetObject("stdout");
if (outf == NULL || outf == Py_None) {
@@ -174,7 +175,7 @@ sys_displayhook(PyObject *self, PyObject *o)
}
if (PyFile_WriteString("\n", outf) != 0)
return NULL;
- if (PyObject_SetAttrString(builtins, "_", o) != 0)
+ if (_PyObject_SetAttrId(builtins, &PyId__, o) != 0)
return NULL;
Py_INCREF(Py_None);
return Py_None;