diff options
author | Thomas Wouters <thomas@python.org> | 2000-08-19 20:55:02 (GMT) |
---|---|---|
committer | Thomas Wouters <thomas@python.org> | 2000-08-19 20:55:02 (GMT) |
commit | 8bad61288186aab93b8aaf6b229c07211e1c77d7 (patch) | |
tree | 2c03c8261f7a1b91c433f20245638154b0629879 /Python | |
parent | 15446d344d2bda98bf8fd7d0244081a9d4bb7c8f (diff) | |
download | cpython-8bad61288186aab93b8aaf6b229c07211e1c77d7.zip cpython-8bad61288186aab93b8aaf6b229c07211e1c77d7.tar.gz cpython-8bad61288186aab93b8aaf6b229c07211e1c77d7.tar.bz2 |
Disallow "import mod.submod as m", because the result is ambiguous. Does it
load mod.submod as m, or mod as m ? Both can be achieved differently, and
unambiguously. Also attempt to document this restriction (editor
appreciated!)
Note that this is an artificial check during compile, because incorporating
this in the grammar is hard, and then adjusting the compiler to do the right
thing with the right nodes is harder.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/compile.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/Python/compile.c b/Python/compile.c index 47445d0..7316790 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -2139,7 +2139,8 @@ com_import_stmt(struct compiling *c, node *n) com_addopname(c, IMPORT_NAME, CHILD(subn, 0)); com_push(c, 1); if (NCH(subn) > 1) { - if (strcmp(STR(CHILD(subn, 1)), "as") != 0) { + if (strcmp(STR(CHILD(subn, 1)), "as") != 0 || + NCH(CHILD(subn, 0)) > 1) { com_error(c, PyExc_SyntaxError, "invalid syntax"); return; |