Make 'as' an actual keyword when with's future statement is used. Not · pythoncapi/cpython@8ae1295 · GitHub
Skip to content

Commit 8ae1295

Browse files
committed
Make 'as' an actual keyword when with's future statement is used. Not
actually necessary for functionality, but good for transition.
1 parent 6cba256 commit 8ae1295

5 files changed

Lines changed: 212 additions & 206 deletions

File tree

Grammar/Grammar

Lines changed: 3 additions & 3 deletions

Parser/parser.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,20 @@ classify(parser_state *ps, int type, char *str)
144144
register label *l = g->g_ll.ll_label;
145145
register int i;
146146
for (i = n; i > 0; i--, l++) {
147-
if (l->lb_type == NAME && l->lb_str != NULL &&
148-
l->lb_str[0] == s[0] &&
149-
strcmp(l->lb_str, s) == 0) {
147+
if (l->lb_type != NAME || l->lb_str == NULL ||
148+
l->lb_str[0] != s[0] ||
149+
strcmp(l->lb_str, s) != 0)
150+
continue;
150151
#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
151-
if (!(ps->p_flags & CO_FUTURE_WITH_STATEMENT) &&
152-
s[0] == 'w' &&
153-
strcmp(s, "with") == 0)
154-
break; /* not a keyword */
155-
#endif
156-
D(printf("It's a keyword\n"));
157-
return n - i;
152+
if (!(ps->p_flags & CO_FUTURE_WITH_STATEMENT)) {
153+
if (s[0] == 'w' && strcmp(s, "with") == 0)
154+
break; /* not a keyword yet */
155+
else if (s[0] == 'a' && strcmp(s, "as") == 0)
156+
break; /* not a keyword yet */
158157
}
158+
#endif
159+
D(printf("It's a keyword\n"));
160+
return n - i;
159161
}
160162
}
161163

Parser/parsetok.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
176176
if (len == 4 && str[0] == 'w' && strcmp(str, "with") == 0)
177177
warn(with_msg, err_ret->filename, tok->lineno);
178178
else if (!(handling_import || handling_with) &&
179-
len == 2 &&
180-
str[0] == 'a' && strcmp(str, "as") == 0)
179+
len == 2 && str[0] == 'a' &&
180+
strcmp(str, "as") == 0)
181181
warn(as_msg, err_ret->filename, tok->lineno);
182182
}
183183
else if (type == NAME &&

Python/ast.c

Lines changed: 2 additions & 2 deletions

0 commit comments

Comments
 (0)