diff options
author | Benjamin Peterson <benjamin@python.org> | 2012-12-06 22:41:04 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2012-12-06 22:41:04 (GMT) |
commit | 442f20996dcd994d1024e5cad7f66a4595352eb2 (patch) | |
tree | 641746efd4247acd2b5e13f5de7f65c026242a05 /Python/compile.c | |
parent | 4b237e3b1112304f834ac78fe05abdecbf3d87b4 (diff) | |
download | cpython-442f20996dcd994d1024e5cad7f66a4595352eb2.zip cpython-442f20996dcd994d1024e5cad7f66a4595352eb2.tar.gz cpython-442f20996dcd994d1024e5cad7f66a4595352eb2.tar.bz2 |
create NameConstant AST class for None, True, and False literals (closes #16619)
Diffstat (limited to 'Python/compile.c')
-rw-r--r-- | Python/compile.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/Python/compile.c b/Python/compile.c index 3cf71ef..3e960cc 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -3194,12 +3194,18 @@ expr_constant(struct compiler *c, expr_ty e) case Name_kind: /* optimize away names that can't be reassigned */ id = PyUnicode_AsUTF8(e->v.Name.id); - if (strcmp(id, "True") == 0) return 1; - if (strcmp(id, "False") == 0) return 0; - if (strcmp(id, "None") == 0) return 0; - if (strcmp(id, "__debug__") == 0) - return ! c->c_optimize; - /* fall through */ + if (id && strcmp(id, "__debug__") == 0) + return !c->c_optimize; + return -1; + case NameConstant_kind: { + PyObject *o = e->v.NameConstant.value; + if (o == Py_None) + return 0; + else if (o == Py_True) + return 1; + else if (o == Py_False) + return 0; + } default: return -1; } @@ -3375,6 +3381,9 @@ compiler_visit_expr(struct compiler *c, expr_ty e) case Ellipsis_kind: ADDOP_O(c, LOAD_CONST, Py_Ellipsis, consts); break; + case NameConstant_kind: + ADDOP_O(c, LOAD_CONST, e->v.NameConstant.value, consts); + break; /* The following exprs can be assignment targets. */ case Attribute_kind: if (e->v.Attribute.ctx != AugStore) |