return 0;
}
+static int exists_not_none(PyObject *obj, _Py_Identifier *id)
+{
+ PyObject *attr = _PyObject_GetAttrId(obj, id);
+ if (!attr) {
+ PyErr_Clear();
+ return 0;
+ }
+ int isnone = attr == Py_None;
+ Py_DECREF(attr);
+ return !isnone;
+}
+
static int init_types(void)
{
PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_returns) && _PyObject_GetAttrId(obj, &PyId_returns) != Py_None) {
+ if (exists_not_none(obj, &PyId_returns)) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_returns);
if (tmp == NULL) goto failed;
PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_starargs) && _PyObject_GetAttrId(obj, &PyId_starargs) != Py_None) {
+ if (exists_not_none(obj, &PyId_starargs)) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_starargs);
if (tmp == NULL) goto failed;
} else {
starargs = NULL;
}
- if (_PyObject_HasAttrId(obj, &PyId_kwargs) && _PyObject_GetAttrId(obj, &PyId_kwargs) != Py_None) {
+ if (exists_not_none(obj, &PyId_kwargs)) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_kwargs);
if (tmp == NULL) goto failed;
if (isinstance) {
expr_ty value;
- if (_PyObject_HasAttrId(obj, &PyId_value) && _PyObject_GetAttrId(obj, &PyId_value) != Py_None) {
+ if (exists_not_none(obj, &PyId_value)) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_value);
if (tmp == NULL) goto failed;
expr_ty exc;
expr_ty cause;
- if (_PyObject_HasAttrId(obj, &PyId_exc) && _PyObject_GetAttrId(obj, &PyId_exc) != Py_None) {
+ if (exists_not_none(obj, &PyId_exc)) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_exc);
if (tmp == NULL) goto failed;
} else {
exc = NULL;
}
- if (_PyObject_HasAttrId(obj, &PyId_cause) && _PyObject_GetAttrId(obj, &PyId_cause) != Py_None) {
+ if (exists_not_none(obj, &PyId_cause)) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_cause);
if (tmp == NULL) goto failed;
PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_msg) && _PyObject_GetAttrId(obj, &PyId_msg) != Py_None) {
+ if (exists_not_none(obj, &PyId_msg)) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_msg);
if (tmp == NULL) goto failed;
asdl_seq* names;
int level;
- if (_PyObject_HasAttrId(obj, &PyId_module) && _PyObject_GetAttrId(obj, &PyId_module) != Py_None) {
+ if (exists_not_none(obj, &PyId_module)) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_module);
if (tmp == NULL) goto failed;
PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_level) && _PyObject_GetAttrId(obj, &PyId_level) != Py_None) {
+ if (exists_not_none(obj, &PyId_level)) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_level);
if (tmp == NULL) goto failed;
if (isinstance) {
expr_ty value;
- if (_PyObject_HasAttrId(obj, &PyId_value) && _PyObject_GetAttrId(obj, &PyId_value) != Py_None) {
+ if (exists_not_none(obj, &PyId_value)) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_value);
if (tmp == NULL) goto failed;
PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_starargs) && _PyObject_GetAttrId(obj, &PyId_starargs) != Py_None) {
+ if (exists_not_none(obj, &PyId_starargs)) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_starargs);
if (tmp == NULL) goto failed;
} else {
starargs = NULL;
}
- if (_PyObject_HasAttrId(obj, &PyId_kwargs) && _PyObject_GetAttrId(obj, &PyId_kwargs) != Py_None) {
+ if (exists_not_none(obj, &PyId_kwargs)) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_kwargs);
if (tmp == NULL) goto failed;
expr_ty upper;
expr_ty step;
- if (_PyObject_HasAttrId(obj, &PyId_lower) && _PyObject_GetAttrId(obj, &PyId_lower) != Py_None) {
+ if (exists_not_none(obj, &PyId_lower)) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_lower);
if (tmp == NULL) goto failed;
} else {
lower = NULL;
}
- if (_PyObject_HasAttrId(obj, &PyId_upper) && _PyObject_GetAttrId(obj, &PyId_upper) != Py_None) {
+ if (exists_not_none(obj, &PyId_upper)) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_upper);
if (tmp == NULL) goto failed;
} else {
upper = NULL;
}
- if (_PyObject_HasAttrId(obj, &PyId_step) && _PyObject_GetAttrId(obj, &PyId_step) != Py_None) {
+ if (exists_not_none(obj, &PyId_step)) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_step);
if (tmp == NULL) goto failed;
identifier name;
asdl_seq* body;
- if (_PyObject_HasAttrId(obj, &PyId_type) && _PyObject_GetAttrId(obj, &PyId_type) != Py_None) {
+ if (exists_not_none(obj, &PyId_type)) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_type);
if (tmp == NULL) goto failed;
} else {
type = NULL;
}
- if (_PyObject_HasAttrId(obj, &PyId_name) && _PyObject_GetAttrId(obj, &PyId_name) != Py_None) {
+ if (exists_not_none(obj, &PyId_name)) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_name);
if (tmp == NULL) goto failed;
PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_vararg) && _PyObject_GetAttrId(obj, &PyId_vararg) != Py_None) {
+ if (exists_not_none(obj, &PyId_vararg)) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_vararg);
if (tmp == NULL) goto failed;
PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_kwarg) && _PyObject_GetAttrId(obj, &PyId_kwarg) != Py_None) {
+ if (exists_not_none(obj, &PyId_kwarg)) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_kwarg);
if (tmp == NULL) goto failed;
PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_annotation) && _PyObject_GetAttrId(obj, &PyId_annotation) != Py_None) {
+ if (exists_not_none(obj, &PyId_annotation)) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_annotation);
if (tmp == NULL) goto failed;
PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_asname) && _PyObject_GetAttrId(obj, &PyId_asname) != Py_None) {
+ if (exists_not_none(obj, &PyId_asname)) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_asname);
if (tmp == NULL) goto failed;
PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_optional_vars) && _PyObject_GetAttrId(obj, &PyId_optional_vars) != Py_None) {
+ if (exists_not_none(obj, &PyId_optional_vars)) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_optional_vars);
if (tmp == NULL) goto failed;