Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Include/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a ``REQ_NAME`` macro to `Include/node.h`.
4 changes: 2 additions & 2 deletions Python/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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:
Expand Down