diff options
author | Terry Jan Reedy <tjreedy@udel.edu> | 2013-03-16 02:52:24 -0400 |
---|---|---|
committer | Terry Jan Reedy <tjreedy@udel.edu> | 2013-03-16 02:52:24 -0400 |
commit | ddf47eb8c61ed4d3ee3ec680336b016b627e53dd (patch) | |
tree | 7c238ff29a60d4957e6e26d336a6163f061d057d /Python/ast.c | |
parent | f612c8fa7c1d6e244200a3eff0a82abcca4cca82 (diff) | |
parent | cdfac6f16bec10dcb4885fd7f74ae80884d0cdf1 (diff) | |
download | cpython-ddf47eb8c61ed4d3ee3ec680336b016b627e53dd.tar.gz |
Merge with 3.3
Diffstat (limited to 'Python/ast.c')
-rw-r--r-- | Python/ast.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/Python/ast.c b/Python/ast.c index 1b5fa6ccc2..aa72cdbb1e 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -282,6 +282,7 @@ validate_expr(expr_ty exp, expr_context_ty ctx) return validate_exprs(exp->v.Tuple.elts, ctx, 0); /* These last cases don't have any checking. */ case Name_kind: + case NameConstant_kind: case Ellipsis_kind: return 1; default: @@ -903,7 +904,7 @@ set_context(struct compiling *c, expr_ty e, expr_context_ty ctx, const node *n) break; case Name_kind: if (ctx == Store) { - if (forbidden_name(c, e->v.Name.id, n, 1)) + if (forbidden_name(c, e->v.Name.id, n, 0)) return 0; /* forbidden_name() calls ast_error() */ } e->v.Name.ctx = ctx; @@ -955,6 +956,9 @@ set_context(struct compiling *c, expr_ty e, expr_context_ty ctx, const node *n) case Bytes_kind: expr_name = "literal"; break; + case NameConstant_kind: + expr_name = "keyword"; + break; case Ellipsis_kind: expr_name = "Ellipsis"; break; @@ -1819,11 +1823,21 @@ ast_for_atom(struct compiling *c, const node *n) switch (TYPE(ch)) { case NAME: { - /* All names start in Load context, but may later be - changed. */ - PyObject *name = NEW_IDENTIFIER(ch); + PyObject *name; + const char *s = STR(ch); + size_t len = strlen(s); + if (len >= 4 && len <= 5) { + if (!strcmp(s, "None")) + return NameConstant(Py_None, LINENO(n), n->n_col_offset, c->c_arena); + if (!strcmp(s, "True")) + return NameConstant(Py_True, LINENO(n), n->n_col_offset, c->c_arena); + if (!strcmp(s, "False")) + return NameConstant(Py_False, LINENO(n), n->n_col_offset, c->c_arena); + } + name = new_identifier(s, c); if (!name) return NULL; + /* All names start in Load context, but may later be changed. */ return Name(name, Load, LINENO(n), n->n_col_offset, c->c_arena); } case STRING: { |