Skip to content
Commits on Source (4)
Metadata-Version: 1.1
Name: typed-ast
Version: 1.3.0
Version: 1.3.1
Summary: a fork of Python 2 and 3 ast modules with type comment support
Home-page: https://github.com/python/typed_ast
Author: David Fisher
......
......@@ -302,6 +302,7 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
}
if (type == TYPE_IGNORE) {
PyObject_FREE(str);
if (!growable_int_array_add(&type_ignores, tok->lineno)) {
err_ret->error = E_NOMEM;
break;
......
......@@ -740,7 +740,14 @@ new_identifier(const char *n, struct compiling *c)
static string
new_type_comment(const char *s, struct compiling *c)
{
return PyUnicode_DecodeUTF8(s, strlen(s), NULL);
PyObject *res = PyUnicode_DecodeUTF8(s, strlen(s), NULL);
if (!res)
return NULL;
if (PyArena_AddPyObject(c->c_arena, res) < 0) {
Py_DECREF(res);
return NULL;
}
return res;
}
#define NEW_TYPE_COMMENT(n) new_type_comment(STR(n), c)
......@@ -1444,6 +1451,8 @@ handle_keywordonly_args(struct compiling *c, const node *n, int start,
case TYPE_COMMENT:
/* arg will be equal to the last argument processed */
arg->type_comment = NEW_TYPE_COMMENT(ch);
if (!arg->type_comment)
goto error;
i += 1;
break;
case DOUBLESTAR:
......@@ -1575,7 +1584,7 @@ ast_for_arguments(struct compiling *c, const node *n)
return NULL;
asdl_seq_SET(posargs, k++, arg);
i += 1; /* the name */
if (TYPE(CHILD(n, i)) == COMMA)
if (i < NCH(n) && TYPE(CHILD(n, i)) == COMMA)
i += 1; /* the comma, if present */
break;
case STAR:
......@@ -1591,7 +1600,7 @@ ast_for_arguments(struct compiling *c, const node *n)
int res = 0;
i += 2; /* now follows keyword only arguments */
if (TYPE(CHILD(n, i)) == TYPE_COMMENT) {
if (i < NCH(n) && TYPE(CHILD(n, i)) == TYPE_COMMENT) {
ast_error(c, CHILD(n, i),
"bare * has associated type comment");
return NULL;
......@@ -1608,11 +1617,13 @@ ast_for_arguments(struct compiling *c, const node *n)
return NULL;
i += 2; /* the star and the name */
if (TYPE(CHILD(n, i)) == COMMA)
if (i < NCH(n) && TYPE(CHILD(n, i)) == COMMA)
i += 1; /* the comma, if present */
if (TYPE(CHILD(n, i)) == TYPE_COMMENT) {
if (i < NCH(n) && TYPE(CHILD(n, i)) == TYPE_COMMENT) {
vararg->type_comment = NEW_TYPE_COMMENT(CHILD(n, i));
if (!vararg->type_comment)
return NULL;
i += 1;
}
......@@ -1644,6 +1655,8 @@ ast_for_arguments(struct compiling *c, const node *n)
/* arg will be equal to the last argument processed */
arg->type_comment = NEW_TYPE_COMMENT(ch);
if (!arg->type_comment)
return NULL;
i += 1;
break;
default:
......@@ -1783,19 +1796,27 @@ ast_for_funcdef_impl(struct compiling *c, const node *n0,
}
if (TYPE(CHILD(n, name_i + 3)) == TYPE_COMMENT) {
type_comment = NEW_TYPE_COMMENT(CHILD(n, name_i + 3));
if (!type_comment)
return NULL;
name_i += 1;
}
body = ast_for_suite(c, CHILD(n, name_i + 3));
if (!body)
return NULL;
if (!type_comment && NCH(CHILD(n, name_i + 3)) > 1) {
/* If the function doesn't have a type comment on the same line, check
* if the suite has a type comment in it. */
if (NCH(CHILD(n, name_i + 3)) > 1) {
/* Check if the suite has a type comment in it. */
tc = CHILD(CHILD(n, name_i + 3), 1);
if (TYPE(tc) == TYPE_COMMENT)
if (TYPE(tc) == TYPE_COMMENT) {
if (type_comment != NULL) {
ast_error(c, n, "Cannot have two type comments on def");
return NULL;
}
type_comment = NEW_TYPE_COMMENT(tc);
if (!type_comment)
return NULL;
}
}
if (is_async)
......@@ -1811,8 +1832,7 @@ ast_for_async_funcdef(struct compiling *c, const node *n, asdl_seq *decorator_se
{
/* async_funcdef: 'async' funcdef */
REQ(n, async_funcdef);
REQ(CHILD(n, 0), NAME);
assert(strcmp(STR(CHILD(n, 0)), "async") == 0);
REQ(CHILD(n, 0), ASYNC);
REQ(CHILD(n, 1), funcdef);
return ast_for_funcdef_impl(c, n, decorator_seq,
......@@ -1833,8 +1853,7 @@ ast_for_async_stmt(struct compiling *c, const node *n)
{
/* async_stmt: 'async' (funcdef | with_stmt | for_stmt) */
REQ(n, async_stmt);
REQ(CHILD(n, 0), NAME);
assert(strcmp(STR(CHILD(n, 0)), "async") == 0);
REQ(CHILD(n, 0), ASYNC);
switch (TYPE(CHILD(n, 1))) {
case funcdef:
......@@ -1952,8 +1971,7 @@ count_comp_fors(struct compiling *c, const node *n)
n_fors++;
REQ(n, comp_for);
if (NCH(n) == 2) {
REQ(CHILD(n, 0), NAME);
assert(strcmp(STR(CHILD(n, 0)), "async") == 0);
REQ(CHILD(n, 0), ASYNC);
n = CHILD(n, 1);
}
else if (NCH(n) == 1) {
......@@ -2038,8 +2056,7 @@ ast_for_comprehension(struct compiling *c, const node *n)
if (NCH(n) == 2) {
is_async = 1;
REQ(CHILD(n, 0), NAME);
assert(strcmp(STR(CHILD(n, 0)), "async") == 0);
REQ(CHILD(n, 0), ASYNC);
sync_n = CHILD(n, 1);
}
else {
......@@ -3281,8 +3298,11 @@ ast_for_expr_stmt(struct compiling *c, const node *n)
expression = ast_for_expr(c, value);
if (!expression)
return NULL;
if (has_type_comment)
if (has_type_comment) {
type_comment = NEW_TYPE_COMMENT(CHILD(n, nch_minus_type));
if (!type_comment)
return NULL;
}
else
type_comment = NULL;
return Assign(targets, expression, type_comment, LINENO(n), n->n_col_offset, c->c_arena);
......@@ -3970,8 +3990,11 @@ ast_for_for_stmt(struct compiling *c, const node *n0, bool is_async)
if (!suite_seq)
return NULL;
if (has_type_comment)
if (has_type_comment) {
type_comment = NEW_TYPE_COMMENT(CHILD(n, 5));
if (!type_comment)
return NULL;
}
else
type_comment = NULL;
......@@ -4162,8 +4185,11 @@ ast_for_with_stmt(struct compiling *c, const node *n0, bool is_async)
if (!body)
return NULL;
if (has_type_comment)
if (has_type_comment) {
type_comment = NEW_TYPE_COMMENT(CHILD(n, NCH(n) - 2));
if (!type_comment)
return NULL;
}
else
type_comment = NULL;
......
python3-typed-ast (1.3.1-1) unstable; urgency=medium
* New upstream version
-- Michael R. Crusoe <michael.crusoe@gmail.com> Fri, 08 Feb 2019 23:11:28 -0800
python3-typed-ast (1.3.0-1) unstable; urgency=medium
* New upstream version
......
Metadata-Version: 1.1
Name: typed-ast
Version: 1.3.0
Version: 1.3.1
Summary: a fork of Python 2 and 3 ast modules with type comment support
Home-page: https://github.com/python/typed_ast
Author: David Fisher
......
__version__ = "1.3.0"
__version__ = "1.3.1"