summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2013-03-18 17:48:58 (GMT)
committerBenjamin Peterson <benjamin@python.org>2013-03-18 17:48:58 (GMT)
commitcda75be02a79686a8e634576600814271536bc1a (patch)
treeb456968bae7bcdebceb833e7b13dae163d732d36 /Python
parentc45e041bff4a5f9aa137dcd4933c72a9221cd7d5 (diff)
downloadcpython-cda75be02a79686a8e634576600814271536bc1a.zip
cpython-cda75be02a79686a8e634576600814271536bc1a.tar.gz
cpython-cda75be02a79686a8e634576600814271536bc1a.tar.bz2
unify some ast.argument's attrs; change Attribute column offset (closes #16795)
Patch from Sven Brauch.
Diffstat (limited to 'Python')
-rw-r--r--Python/Python-ast.c183
-rw-r--r--Python/ast.c72
-rw-r--r--Python/compile.c12
-rw-r--r--Python/symtable.c12
4 files changed, 121 insertions, 158 deletions
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index b940417..5e387f8 100644
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -412,24 +412,24 @@ static char *ExceptHandler_fields[]={
static PyTypeObject *arguments_type;
static PyObject* ast2obj_arguments(void*);
_Py_IDENTIFIER(vararg);
-_Py_IDENTIFIER(varargannotation);
_Py_IDENTIFIER(kwonlyargs);
+_Py_IDENTIFIER(kw_defaults);
_Py_IDENTIFIER(kwarg);
-_Py_IDENTIFIER(kwargannotation);
_Py_IDENTIFIER(defaults);
-_Py_IDENTIFIER(kw_defaults);
static char *arguments_fields[]={
"args",
"vararg",
- "varargannotation",
"kwonlyargs",
+ "kw_defaults",
"kwarg",
- "kwargannotation",
"defaults",
- "kw_defaults",
};
static PyTypeObject *arg_type;
static PyObject* ast2obj_arg(void*);
+static char *arg_attributes[] = {
+ "lineno",
+ "col_offset",
+};
_Py_IDENTIFIER(arg);
_Py_IDENTIFIER(annotation);
static char *arg_fields[]={
@@ -1056,6 +1056,7 @@ static int init_types(void)
comprehension_type = make_type("comprehension", &AST_type,
comprehension_fields, 3);
if (!comprehension_type) return 0;
+ if (!add_attributes(comprehension_type, NULL, 0)) return 0;
excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0);
if (!excepthandler_type) return 0;
if (!add_attributes(excepthandler_type, excepthandler_attributes, 2))
@@ -1063,16 +1064,21 @@ static int init_types(void)
ExceptHandler_type = make_type("ExceptHandler", excepthandler_type,
ExceptHandler_fields, 3);
if (!ExceptHandler_type) return 0;
- arguments_type = make_type("arguments", &AST_type, arguments_fields, 8);
+ arguments_type = make_type("arguments", &AST_type, arguments_fields, 6);
if (!arguments_type) return 0;
+ if (!add_attributes(arguments_type, NULL, 0)) return 0;
arg_type = make_type("arg", &AST_type, arg_fields, 2);
if (!arg_type) return 0;
+ if (!add_attributes(arg_type, arg_attributes, 2)) return 0;
keyword_type = make_type("keyword", &AST_type, keyword_fields, 2);
if (!keyword_type) return 0;
+ if (!add_attributes(keyword_type, NULL, 0)) return 0;
alias_type = make_type("alias", &AST_type, alias_fields, 2);
if (!alias_type) return 0;
+ if (!add_attributes(alias_type, NULL, 0)) return 0;
withitem_type = make_type("withitem", &AST_type, withitem_fields, 2);
if (!withitem_type) return 0;
+ if (!add_attributes(withitem_type, NULL, 0)) return 0;
initialized = 1;
return 1;
}
@@ -2213,9 +2219,8 @@ ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
}
arguments_ty
-arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation,
- asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation,
- asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena)
+arguments(asdl_seq * args, arg_ty vararg, asdl_seq * kwonlyargs, asdl_seq *
+ kw_defaults, arg_ty kwarg, asdl_seq * defaults, PyArena *arena)
{
arguments_ty p;
p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
@@ -2223,12 +2228,10 @@ arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation,
return NULL;
p->args = args;
p->vararg = vararg;
- p->varargannotation = varargannotation;
p->kwonlyargs = kwonlyargs;
+ p->kw_defaults = kw_defaults;
p->kwarg = kwarg;
- p->kwargannotation = kwargannotation;
p->defaults = defaults;
- p->kw_defaults = kw_defaults;
return p;
}
@@ -3413,29 +3416,24 @@ ast2obj_arguments(void* _o)
if (_PyObject_SetAttrId(result, &PyId_args, value) == -1)
goto failed;
Py_DECREF(value);
- value = ast2obj_identifier(o->vararg);
+ value = ast2obj_arg(o->vararg);
if (!value) goto failed;
if (_PyObject_SetAttrId(result, &PyId_vararg, value) == -1)
goto failed;
Py_DECREF(value);
- value = ast2obj_expr(o->varargannotation);
- if (!value) goto failed;
- 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_SetAttrId(result, &PyId_kwonlyargs, value) == -1)
goto failed;
Py_DECREF(value);
- value = ast2obj_identifier(o->kwarg);
+ value = ast2obj_list(o->kw_defaults, ast2obj_expr);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1)
+ if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1)
goto failed;
Py_DECREF(value);
- value = ast2obj_expr(o->kwargannotation);
+ value = ast2obj_arg(o->kwarg);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_kwargannotation, value) == -1)
+ if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_list(o->defaults, ast2obj_expr);
@@ -3443,11 +3441,6 @@ ast2obj_arguments(void* _o)
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_SetAttrId(result, &PyId_kw_defaults, value) == -1)
- goto failed;
- Py_DECREF(value);
return result;
failed:
Py_XDECREF(value);
@@ -3477,6 +3470,16 @@ ast2obj_arg(void* _o)
if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1)
goto failed;
Py_DECREF(value);
+ value = ast2obj_int(o->lineno);
+ if (!value) goto failed;
+ 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_SetAttrId(result, &PyId_col_offset, value) < 0)
+ goto failed;
+ Py_DECREF(value);
return result;
failed:
Py_XDECREF(value);
@@ -3843,7 +3846,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_returns)) {
+ if (_PyObject_HasAttrId(obj, &PyId_returns) && _PyObject_GetAttrId(obj, &PyId_returns) != Py_None) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_returns);
if (tmp == NULL) goto failed;
@@ -3934,7 +3937,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_starargs)) {
+ if (_PyObject_HasAttrId(obj, &PyId_starargs) && _PyObject_GetAttrId(obj, &PyId_starargs) != Py_None) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_starargs);
if (tmp == NULL) goto failed;
@@ -3945,7 +3948,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
} else {
starargs = NULL;
}
- if (_PyObject_HasAttrId(obj, &PyId_kwargs)) {
+ if (_PyObject_HasAttrId(obj, &PyId_kwargs) && _PyObject_GetAttrId(obj, &PyId_kwargs) != Py_None) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_kwargs);
if (tmp == NULL) goto failed;
@@ -4018,7 +4021,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
if (isinstance) {
expr_ty value;
- if (_PyObject_HasAttrId(obj, &PyId_value)) {
+ if (_PyObject_HasAttrId(obj, &PyId_value) && _PyObject_GetAttrId(obj, &PyId_value) != Py_None) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_value);
if (tmp == NULL) goto failed;
@@ -4476,7 +4479,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
expr_ty exc;
expr_ty cause;
- if (_PyObject_HasAttrId(obj, &PyId_exc)) {
+ if (_PyObject_HasAttrId(obj, &PyId_exc) && _PyObject_GetAttrId(obj, &PyId_exc) != Py_None) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_exc);
if (tmp == NULL) goto failed;
@@ -4487,7 +4490,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
} else {
exc = NULL;
}
- if (_PyObject_HasAttrId(obj, &PyId_cause)) {
+ if (_PyObject_HasAttrId(obj, &PyId_cause) && _PyObject_GetAttrId(obj, &PyId_cause) != Py_None) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_cause);
if (tmp == NULL) goto failed;
@@ -4637,7 +4640,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_msg)) {
+ if (_PyObject_HasAttrId(obj, &PyId_msg) && _PyObject_GetAttrId(obj, &PyId_msg) != Py_None) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_msg);
if (tmp == NULL) goto failed;
@@ -4697,7 +4700,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
asdl_seq* names;
int level;
- if (_PyObject_HasAttrId(obj, &PyId_module)) {
+ if (_PyObject_HasAttrId(obj, &PyId_module) && _PyObject_GetAttrId(obj, &PyId_module) != Py_None) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_module);
if (tmp == NULL) goto failed;
@@ -4733,7 +4736,7 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_level)) {
+ if (_PyObject_HasAttrId(obj, &PyId_level) && _PyObject_GetAttrId(obj, &PyId_level) != Py_None) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_level);
if (tmp == NULL) goto failed;
@@ -5452,7 +5455,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
if (isinstance) {
expr_ty value;
- if (_PyObject_HasAttrId(obj, &PyId_value)) {
+ if (_PyObject_HasAttrId(obj, &PyId_value) && _PyObject_GetAttrId(obj, &PyId_value) != Py_None) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_value);
if (tmp == NULL) goto failed;
@@ -5639,7 +5642,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_starargs)) {
+ if (_PyObject_HasAttrId(obj, &PyId_starargs) && _PyObject_GetAttrId(obj, &PyId_starargs) != Py_None) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_starargs);
if (tmp == NULL) goto failed;
@@ -5650,7 +5653,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
} else {
starargs = NULL;
}
- if (_PyObject_HasAttrId(obj, &PyId_kwargs)) {
+ if (_PyObject_HasAttrId(obj, &PyId_kwargs) && _PyObject_GetAttrId(obj, &PyId_kwargs) != Py_None) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_kwargs);
if (tmp == NULL) goto failed;
@@ -6121,7 +6124,7 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
expr_ty upper;
expr_ty step;
- if (_PyObject_HasAttrId(obj, &PyId_lower)) {
+ if (_PyObject_HasAttrId(obj, &PyId_lower) && _PyObject_GetAttrId(obj, &PyId_lower) != Py_None) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_lower);
if (tmp == NULL) goto failed;
@@ -6132,7 +6135,7 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
} else {
lower = NULL;
}
- if (_PyObject_HasAttrId(obj, &PyId_upper)) {
+ if (_PyObject_HasAttrId(obj, &PyId_upper) && _PyObject_GetAttrId(obj, &PyId_upper) != Py_None) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_upper);
if (tmp == NULL) goto failed;
@@ -6143,7 +6146,7 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
} else {
upper = NULL;
}
- if (_PyObject_HasAttrId(obj, &PyId_step)) {
+ if (_PyObject_HasAttrId(obj, &PyId_step) && _PyObject_GetAttrId(obj, &PyId_step) != Py_None) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_step);
if (tmp == NULL) goto failed;
@@ -6598,7 +6601,7 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
identifier name;
asdl_seq* body;
- if (_PyObject_HasAttrId(obj, &PyId_type)) {
+ if (_PyObject_HasAttrId(obj, &PyId_type) && _PyObject_GetAttrId(obj, &PyId_type) != Py_None) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_type);
if (tmp == NULL) goto failed;
@@ -6609,7 +6612,7 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
} else {
type = NULL;
}
- if (_PyObject_HasAttrId(obj, &PyId_name)) {
+ if (_PyObject_HasAttrId(obj, &PyId_name) && _PyObject_GetAttrId(obj, &PyId_name) != Py_None) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_name);
if (tmp == NULL) goto failed;
@@ -6662,13 +6665,11 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
{
PyObject* tmp = NULL;
asdl_seq* args;
- identifier vararg;
- expr_ty varargannotation;
+ arg_ty vararg;
asdl_seq* kwonlyargs;
- identifier kwarg;
- expr_ty kwargannotation;
- asdl_seq* defaults;
asdl_seq* kw_defaults;
+ arg_ty kwarg;
+ asdl_seq* defaults;
if (_PyObject_HasAttrId(obj, &PyId_args)) {
int res;
@@ -6695,28 +6696,17 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_vararg)) {
+ if (_PyObject_HasAttrId(obj, &PyId_vararg) && _PyObject_GetAttrId(obj, &PyId_vararg) != Py_None) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_vararg);
if (tmp == NULL) goto failed;
- res = obj2ast_identifier(tmp, &vararg, arena);
+ res = obj2ast_arg(tmp, &vararg, arena);
if (res != 0) goto failed;
Py_XDECREF(tmp);
tmp = NULL;
} else {
vararg = NULL;
}
- if (_PyObject_HasAttrId(obj, &PyId_varargannotation)) {
- int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_varargannotation);
- if (tmp == NULL) goto failed;
- res = obj2ast_expr(tmp, &varargannotation, arena);
- if (res != 0) goto failed;
- Py_XDECREF(tmp);
- tmp = NULL;
- } else {
- varargannotation = NULL;
- }
if (_PyObject_HasAttrId(obj, &PyId_kwonlyargs)) {
int res;
Py_ssize_t len;
@@ -6742,27 +6732,41 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_kwarg)) {
+ if (_PyObject_HasAttrId(obj, &PyId_kw_defaults)) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_kwarg);
+ Py_ssize_t len;
+ Py_ssize_t i;
+ tmp = _PyObject_GetAttrId(obj, &PyId_kw_defaults);
if (tmp == NULL) goto failed;
- res = obj2ast_identifier(tmp, &kwarg, arena);
- if (res != 0) 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);
+ goto failed;
+ }
+ len = PyList_GET_SIZE(tmp);
+ kw_defaults = asdl_seq_new(len, arena);
+ if (kw_defaults == NULL) goto failed;
+ for (i = 0; i < len; i++) {
+ expr_ty value;
+ res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
+ if (res != 0) goto failed;
+ asdl_seq_SET(kw_defaults, i, value);
+ }
Py_XDECREF(tmp);
tmp = NULL;
} else {
- kwarg = NULL;
+ PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments");
+ return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_kwargannotation)) {
+ if (_PyObject_HasAttrId(obj, &PyId_kwarg) && _PyObject_GetAttrId(obj, &PyId_kwarg) != Py_None) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_kwargannotation);
+ tmp = _PyObject_GetAttrId(obj, &PyId_kwarg);
if (tmp == NULL) goto failed;
- res = obj2ast_expr(tmp, &kwargannotation, arena);
+ res = obj2ast_arg(tmp, &kwarg, arena);
if (res != 0) goto failed;
Py_XDECREF(tmp);
tmp = NULL;
} else {
- kwargannotation = NULL;
+ kwarg = NULL;
}
if (_PyObject_HasAttrId(obj, &PyId_defaults)) {
int res;
@@ -6789,33 +6793,8 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_kw_defaults)) {
- int res;
- Py_ssize_t len;
- Py_ssize_t i;
- 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);
- goto failed;
- }
- len = PyList_GET_SIZE(tmp);
- kw_defaults = asdl_seq_new(len, arena);
- if (kw_defaults == NULL) goto failed;
- for (i = 0; i < len; i++) {
- expr_ty value;
- res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
- if (res != 0) goto failed;
- asdl_seq_SET(kw_defaults, i, value);
- }
- Py_XDECREF(tmp);
- tmp = NULL;
- } else {
- PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments");
- return 1;
- }
- *out = arguments(args, vararg, varargannotation, kwonlyargs, kwarg,
- kwargannotation, defaults, kw_defaults, arena);
+ *out = arguments(args, vararg, kwonlyargs, kw_defaults, kwarg,
+ defaults, arena);
return 0;
failed:
Py_XDECREF(tmp);
@@ -6841,7 +6820,7 @@ obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_annotation)) {
+ if (_PyObject_HasAttrId(obj, &PyId_annotation) && _PyObject_GetAttrId(obj, &PyId_annotation) != Py_None) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_annotation);
if (tmp == NULL) goto failed;
@@ -6916,7 +6895,7 @@ obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_asname)) {
+ if (_PyObject_HasAttrId(obj, &PyId_asname) && _PyObject_GetAttrId(obj, &PyId_asname) != Py_None) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_asname);
if (tmp == NULL) goto failed;
@@ -6953,7 +6932,7 @@ obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_optional_vars)) {
+ if (_PyObject_HasAttrId(obj, &PyId_optional_vars) && _PyObject_GetAttrId(obj, &PyId_optional_vars) != Py_None) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_optional_vars);
if (tmp == NULL) goto failed;
diff --git a/Python/ast.c b/Python/ast.c
index aa72cdb..2080e49 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -109,22 +109,14 @@ validate_arguments(arguments_ty args)
{
if (!validate_args(args->args))
return 0;
- if (args->varargannotation) {
- if (!args->vararg) {
- PyErr_SetString(PyExc_ValueError, "varargannotation but no vararg on arguments");
- return 0;
- }
- if (!validate_expr(args->varargannotation, Load))
+ if (args->vararg && args->vararg->annotation
+ && !validate_expr(args->vararg->annotation, Load)) {
return 0;
}
if (!validate_args(args->kwonlyargs))
return 0;
- if (args->kwargannotation) {
- if (!args->kwarg) {
- PyErr_SetString(PyExc_ValueError, "kwargannotation but no kwarg on arguments");
- return 0;
- }
- if (!validate_expr(args->kwargannotation, Load))
+ if (args->kwarg && args->kwarg->annotation
+ && !validate_expr(args->kwarg->annotation, Load)) {
return 0;
}
if (asdl_seq_LEN(args->defaults) > asdl_seq_LEN(args->args)) {
@@ -1138,7 +1130,13 @@ ast_for_arg(struct compiling *c, const node *n)
return NULL;
}
- return arg(name, annotation, c->c_arena);
+ arg_ty tmp = arg(name, annotation, c->c_arena);
+ if (!tmp)
+ return NULL;
+
+ tmp->lineno = LINENO(n);
+ tmp->col_offset = n->n_col_offset;
+ return tmp;
}
/* returns -1 if failed to handle keyword only arguments
@@ -1234,15 +1232,13 @@ ast_for_arguments(struct compiling *c, const node *n)
int i, j, k, nposargs = 0, nkwonlyargs = 0;
int nposdefaults = 0, found_default = 0;
asdl_seq *posargs, *posdefaults, *kwonlyargs, *kwdefaults;
- identifier vararg = NULL, kwarg = NULL;
+ arg_ty vararg = NULL, kwarg = NULL;
arg_ty arg;
- expr_ty varargannotation = NULL, kwargannotation = NULL;
node *ch;
if (TYPE(n) == parameters) {
if (NCH(n) == 2) /* () as argument list */
- return arguments(NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, c->c_arena);
+ return arguments(NULL, NULL, NULL, NULL, NULL, NULL, c->c_arena);
n = CHILD(n, 1);
}
assert(TYPE(n) == typedargslist || TYPE(n) == varargslist);
@@ -1348,17 +1344,10 @@ ast_for_arguments(struct compiling *c, const node *n)
i = res; /* res has new position to process */
}
else {
- vararg = NEW_IDENTIFIER(CHILD(ch, 0));
+ vararg = ast_for_arg(c, ch);
if (!vararg)
return NULL;
- if (forbidden_name(c, vararg, CHILD(ch, 0), 0))
- return NULL;
- if (NCH(ch) > 1) {
- /* there is an annotation on the vararg */
- varargannotation = ast_for_expr(c, CHILD(ch, 2));
- if (!varargannotation)
- return NULL;
- }
+
i += 3;
if (i < NCH(n) && (TYPE(CHILD(n, i)) == tfpdef
|| TYPE(CHILD(n, i)) == vfpdef)) {
@@ -1373,17 +1362,9 @@ ast_for_arguments(struct compiling *c, const node *n)
case DOUBLESTAR:
ch = CHILD(n, i+1); /* tfpdef */
assert(TYPE(ch) == tfpdef || TYPE(ch) == vfpdef);
- kwarg = NEW_IDENTIFIER(CHILD(ch, 0));
+ kwarg = ast_for_arg(c, ch);
if (!kwarg)
return NULL;
- if (NCH(ch) > 1) {
- /* there is an annotation on the kwarg */
- kwargannotation = ast_for_expr(c, CHILD(ch, 2));
- if (!kwargannotation)
- return NULL;
- }
- if (forbidden_name(c, kwarg, CHILD(ch, 0), 0))
- return NULL;
i += 3;
break;
default:
@@ -1393,8 +1374,7 @@ ast_for_arguments(struct compiling *c, const node *n)
return NULL;
}
}
- return arguments(posargs, vararg, varargannotation, kwonlyargs, kwarg,
- kwargannotation, posdefaults, kwdefaults, c->c_arena);
+ return arguments(posargs, vararg, kwonlyargs, kwdefaults, kwarg, posdefaults, c->c_arena);
}
static expr_ty
@@ -1559,8 +1539,7 @@ ast_for_lambdef(struct compiling *c, const node *n)
expr_ty expression;
if (NCH(n) == 3) {
- args = arguments(NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, c->c_arena);
+ args = arguments(NULL, NULL, NULL, NULL, NULL, NULL, c->c_arena);
if (!args)
return NULL;
expression = ast_for_expr(c, CHILD(n, 2));
@@ -2107,15 +2086,22 @@ ast_for_trailer(struct compiling *c, const node *n, expr_ty left_expr)
if (NCH(n) == 2)
return Call(left_expr, NULL, NULL, NULL, NULL, LINENO(n),
n->n_col_offset, c->c_arena);
- else
- return ast_for_call(c, CHILD(n, 1), left_expr);
+ else {
+ expr_ty tmp = ast_for_call(c, CHILD(n, 1), left_expr);
+ if (!tmp)
+ return NULL;
+
+ tmp->lineno = LINENO(n);
+ tmp->col_offset = n->n_col_offset;
+ return tmp;
+ }
}
else if (TYPE(CHILD(n, 0)) == DOT ) {
PyObject *attr_id = NEW_IDENTIFIER(CHILD(n, 1));
if (!attr_id)
return NULL;
return Attribute(left_expr, attr_id, Load,
- LINENO(n), n->n_col_offset, c->c_arena);
+ LINENO(CHILD(n, 1)), CHILD(n, 1)->n_col_offset, c->c_arena);
}
else {
REQ(CHILD(n, 0), LSQB);
@@ -2216,8 +2202,6 @@ ast_for_power(struct compiling *c, const node *n)
tmp = ast_for_trailer(c, ch, e);
if (!tmp)
return NULL;
- tmp->lineno = e->lineno;
- tmp->col_offset = e->col_offset;
e = tmp;
}
if (TYPE(CHILD(n, NCH(n) - 1)) == factor) {
diff --git a/Python/compile.c b/Python/compile.c
index 61f35f8..0aca8bd 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1498,15 +1498,15 @@ compiler_visit_annotations(struct compiler *c, arguments_ty args,
if (compiler_visit_argannotations(c, args->args, names))
goto error;
- if (args->varargannotation &&
- compiler_visit_argannotation(c, args->vararg,
- args->varargannotation, names))
+ if (args->vararg && args->vararg->annotation &&
+ compiler_visit_argannotation(c, args->vararg->arg,
+ args->vararg->annotation, names))
goto error;
if (compiler_visit_argannotations(c, args->kwonlyargs, names))
goto error;
- if (args->kwargannotation &&
- compiler_visit_argannotation(c, args->kwarg,
- args->kwargannotation, names))
+ if (args->kwarg && args->kwarg->annotation &&
+ compiler_visit_argannotation(c, args->kwarg->arg,
+ args->kwarg->annotation, names))
goto error;
if (!return_str) {
diff --git a/Python/symtable.c b/Python/symtable.c
index d16bfbc..b9ca615 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -1530,10 +1530,10 @@ symtable_visit_annotations(struct symtable *st, stmt_ty s)
if (a->args && !symtable_visit_argannotations(st, a->args))
return 0;
- if (a->varargannotation)
- VISIT(st, expr, a->varargannotation);
- if (a->kwargannotation)
- VISIT(st, expr, a->kwargannotation);
+ if (a->vararg && a->vararg->annotation)
+ VISIT(st, expr, a->vararg->annotation);
+ if (a->kwarg && a->kwarg->annotation)
+ VISIT(st, expr, a->kwarg->annotation);
if (a->kwonlyargs && !symtable_visit_argannotations(st, a->kwonlyargs))
return 0;
if (s->v.FunctionDef.returns)
@@ -1552,12 +1552,12 @@ symtable_visit_arguments(struct symtable *st, arguments_ty a)
if (a->kwonlyargs && !symtable_visit_params(st, a->kwonlyargs))
return 0;
if (a->vararg) {
- if (!symtable_add_def(st, a->vararg, DEF_PARAM))
+ if (!symtable_add_def(st, a->vararg->arg, DEF_PARAM))
return 0;
st->st_cur->ste_varargs = 1;
}
if (a->kwarg) {
- if (!symtable_add_def(st, a->kwarg, DEF_PARAM))
+ if (!symtable_add_def(st, a->kwarg->arg, DEF_PARAM))
return 0;
st->st_cur->ste_varkeywords = 1;
}