diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-03-22 03:51:05 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-03-22 03:51:05 (GMT) |
commit | 280e6bd742a50cf7f00739c7904f1b5aa66bdad9 (patch) | |
tree | 4cf258e6f5a0c6bc173cc392c406716bc6b1de17 | |
parent | 6e9c0baa659a2e28d0d4c979ec69d3a6e545643b (diff) | |
download | cpython-280e6bd742a50cf7f00739c7904f1b5aa66bdad9.zip cpython-280e6bd742a50cf7f00739c7904f1b5aa66bdad9.tar.gz cpython-280e6bd742a50cf7f00739c7904f1b5aa66bdad9.tar.bz2 |
Make error messages clearer for illegal combinations of nested
functions and import */exec.
-rw-r--r-- | Python/compile.c | 51 |
1 files changed, 36 insertions, 15 deletions
diff --git a/Python/compile.c b/Python/compile.c index 81be103..fe84921 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -4191,32 +4191,53 @@ symtable_check_unoptimized(struct compiling *c, || (ste->ste_nested && si->si_nimplicit))) return 0; +#define ILLEGAL_CONTAINS "contains a nested function with free variables" + +#define ILLEGAL_IS "is a nested function" + #define ILLEGAL_IMPORT_STAR \ -"import * is not allowed in function '%.100s' " \ -"because it contains a nested function with free variables" +"import * is not allowed in function '%.100s' because it %s" #define ILLEGAL_BARE_EXEC \ -"unqualified exec is not allowed in function '%.100s' " \ -"because it contains a nested function with free variables" +"unqualified exec is not allowed in function '%.100s' it %s" #define ILLEGAL_EXEC_AND_IMPORT_STAR \ "function '%.100s' uses import * and bare exec, which are illegal" \ -"because it contains a nested function with free variables" +"because it %s" /* XXX perhaps the linenos for these opt-breaking statements should be stored so the exception can point to them. */ - if (ste->ste_optimized == OPT_IMPORT_STAR) - sprintf(buf, ILLEGAL_IMPORT_STAR, - PyString_AS_STRING(ste->ste_name)); - else if (ste->ste_optimized == (OPT_BARE_EXEC | OPT_EXEC)) - sprintf(buf, ILLEGAL_BARE_EXEC, - PyString_AS_STRING(ste->ste_name)); - else { - sprintf(buf, ILLEGAL_EXEC_AND_IMPORT_STAR, - PyString_AS_STRING(ste->ste_name)); + if (ste->ste_child_free) { + if (ste->ste_optimized == OPT_IMPORT_STAR) + sprintf(buf, ILLEGAL_IMPORT_STAR, + PyString_AS_STRING(ste->ste_name), + ILLEGAL_CONTAINS); + else if (ste->ste_optimized == (OPT_BARE_EXEC | OPT_EXEC)) + sprintf(buf, ILLEGAL_BARE_EXEC, + PyString_AS_STRING(ste->ste_name), + ILLEGAL_CONTAINS); + else { + sprintf(buf, ILLEGAL_EXEC_AND_IMPORT_STAR, + PyString_AS_STRING(ste->ste_name), + ILLEGAL_CONTAINS); + } + } else { + if (ste->ste_optimized == OPT_IMPORT_STAR) + sprintf(buf, ILLEGAL_IMPORT_STAR, + PyString_AS_STRING(ste->ste_name), + ILLEGAL_IS); + else if (ste->ste_optimized == (OPT_BARE_EXEC | OPT_EXEC)) + sprintf(buf, ILLEGAL_BARE_EXEC, + PyString_AS_STRING(ste->ste_name), + ILLEGAL_IS); + else { + sprintf(buf, ILLEGAL_EXEC_AND_IMPORT_STAR, + PyString_AS_STRING(ste->ste_name), + ILLEGAL_IS); + } } - + if (c->c_symtable->st_nested_scopes) { PyErr_SetString(PyExc_SyntaxError, buf); PyErr_SyntaxLocation(c->c_symtable->st_filename, |