diff --git a/Include/node.h b/Include/node.h index 2b3907409738733..915cd83f968c91d 100644 --- a/Include/node.h +++ b/Include/node.h @@ -38,6 +38,11 @@ PyAPI_FUNC(Py_ssize_t) _PyNode_SizeOf(node *n); /* Assert that the type of a node is what we expect */ #define REQ(n, type) assert(TYPE(n) == (type)) +/* Assert that a NAME node contains the expected name */ +#define REQ_NAME(node, name) do { \ + REQ((node), NAME); \ + assert(strcmp(STR((node)), (name)) == 0); \ +} while(0) PyAPI_FUNC(void) PyNode_ListTree(node *); void _PyNode_FinalizeEndPos(node *n); // helper also used in parsetok.c diff --git a/Misc/NEWS.d/next/Core and Builtins/2017-10-08-22-21-27.bpo-31698.ekxKQc.rst b/Misc/NEWS.d/next/Core and Builtins/2017-10-08-22-21-27.bpo-31698.ekxKQc.rst new file mode 100644 index 000000000000000..b9c509b58f85af5 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2017-10-08-22-21-27.bpo-31698.ekxKQc.rst @@ -0,0 +1 @@ +Add a ``REQ_NAME`` macro to `Include/node.h`. diff --git a/Python/ast.c b/Python/ast.c index 9c48d71d154fcc4..3f5d852e68f90da 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -2032,7 +2032,7 @@ count_comp_fors(struct compiling *c, const node *n) n_fors++; REQ(n, comp_for); if (NCH(n) == 2) { - REQ(CHILD(n, 0), ASYNC); + REQ_NAME(CHILD(n, 0), "async"); n = CHILD(n, 1); } else if (NCH(n) == 1) { @@ -2917,7 +2917,7 @@ ast_for_expr(struct compiling *c, const node *n) return BoolOp(And, seq, LINENO(n), n->n_col_offset, n->n_end_lineno, n->n_end_col_offset, c->c_arena); - assert(!strcmp(STR(CHILD(n, 1)), "or")); + REQ_NAME(CHILD(n, 1), "or"); return BoolOp(Or, seq, LINENO(n), n->n_col_offset, n->n_end_lineno, n->n_end_col_offset, c->c_arena); case not_test: