mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
Patch #1550800: make exec a function.
This commit is contained in:
parent
4e472e05bd
commit
7cae87ca7b
105 changed files with 1246 additions and 1583 deletions
|
@ -480,8 +480,7 @@ check_unoptimized(const PySTEntryObject* ste) {
|
|||
"is a nested function");
|
||||
|
||||
switch (ste->ste_unoptimized) {
|
||||
case OPT_TOPLEVEL: /* exec / import * at top-level is fine */
|
||||
case OPT_EXEC: /* qualified exec is fine */
|
||||
case OPT_TOPLEVEL: /* import * at top-level is fine */
|
||||
return 1;
|
||||
case OPT_IMPORT_STAR:
|
||||
PyOS_snprintf(buf, sizeof(buf),
|
||||
|
@ -489,18 +488,6 @@ check_unoptimized(const PySTEntryObject* ste) {
|
|||
"because it is %s",
|
||||
PyString_AS_STRING(ste->ste_name), trailer);
|
||||
break;
|
||||
case OPT_BARE_EXEC:
|
||||
PyOS_snprintf(buf, sizeof(buf),
|
||||
"unqualified exec is not allowed in function "
|
||||
"'%.100s' it %s",
|
||||
PyString_AS_STRING(ste->ste_name), trailer);
|
||||
break;
|
||||
default:
|
||||
PyOS_snprintf(buf, sizeof(buf),
|
||||
"function '%.100s' uses import * and bare exec, "
|
||||
"which are illegal because it %s",
|
||||
PyString_AS_STRING(ste->ste_name), trailer);
|
||||
break;
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_SyntaxError, buf);
|
||||
|
@ -1045,19 +1032,6 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
|
|||
if (st->st_cur->ste_unoptimized && !st->st_cur->ste_opt_lineno)
|
||||
st->st_cur->ste_opt_lineno = s->lineno;
|
||||
break;
|
||||
case Exec_kind:
|
||||
VISIT(st, expr, s->v.Exec.body);
|
||||
if (!st->st_cur->ste_opt_lineno)
|
||||
st->st_cur->ste_opt_lineno = s->lineno;
|
||||
if (s->v.Exec.globals) {
|
||||
st->st_cur->ste_unoptimized |= OPT_EXEC;
|
||||
VISIT(st, expr, s->v.Exec.globals);
|
||||
if (s->v.Exec.locals)
|
||||
VISIT(st, expr, s->v.Exec.locals);
|
||||
} else {
|
||||
st->st_cur->ste_unoptimized |= OPT_BARE_EXEC;
|
||||
}
|
||||
break;
|
||||
case Global_kind: {
|
||||
int i;
|
||||
asdl_seq *seq = s->v.Global.names;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue