8000 Raise error if there isn't already one · python/cpython@e4778a8 · GitHub
[go: up one dir, main page]

Skip to content

Commit e4778a8

Browse files
committed
Raise error if there isn't already one
1 parent 6cdbcb4 commit e4778a8

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

Python/ast.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ validate_arguments(arguments_ty args)
111111
static int
112112
validate_constant(PyObject *value)
113113
{
114-
PyObject *invalid_value = value;
115-
116114
if (value == Py_None || value == Py_Ellipsis)
117115
return 1;
118116

@@ -128,25 +126,23 @@ validate_constant(PyObject *value)
128126
PyObject *it;
129127

130128
it = PyObject_GetIter(value);
131-
if (it == NULL) {
132-
goto invalid;
133-
}
129+
if (it == NULL)
130+
return 0;
134131

135132
while (1) {
136133
PyObject *item = PyIter_Next(it);
137134
if (item == NULL) {
138135
if (PyErr_Occurred()) {
139136
Py_DECREF(it);
140-
goto invalid;
137+
return 0;
141138
}
142139
break;
143140
}
144141

145142
if (!validate_constant(item)) {
146-
invalid_value = item;
147143
Py_DECREF(it);
148144
Py_DECREF(item);
149-
goto invalid;
145+
return 0;
150146
}
151147
Py_DECREF(item);
152148
}
@@ -155,12 +151,11 @@ validate_constant(PyObject *value)
155151
return 1;
156152
}
157153

158-
goto invalid;
159-
160-
invalid:
161-
PyErr_Format(PyExc_TypeError,
162-
"got an invalid type in Constant: %s",
163-
_PyType_Name(Py_TYPE(invalid_value)));
154+
if (!PyErr_Occurred()) {
155+
PyErr_Format(PyExc_TypeError,
156+
"got an invalid type in Constant: %s",
157+
_PyType_Name(Py_TYPE(value)));
158+
}
164159
return 0;
165160
}
166161

0 commit comments

Comments
 (0)
0