From d1f5a59edb56b64336f07fc88cff6cbebed12dd6 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sat, 13 Jun 2009 13:06:21 +0000 Subject: allow importing from a module named None if it has an 'as' clause --- Lib/test/test_compile.py | 2 ++ Python/ast.c | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index 4e15d8c..6ffd64a 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -281,6 +281,8 @@ if 1: self.assertRaises(SyntaxError, compile, stmt, 'tmp', 'exec') # This is ok. compile("from None import x", "tmp", "exec") + compile("from x import None as y", "tmp", "exec") + compile("import None as x", "tmp", "exec") def test_import(self): succeed = [ diff --git a/Python/ast.c b/Python/ast.c index 9639350..d259259 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -2316,8 +2316,10 @@ alias_for_import_name(struct compiling *c, const node *n, int store) if (!str) return NULL; } - if (!forbidden_check(c, name_node, STR(name_node))) - return NULL; + else { + if (!forbidden_check(c, name_node, STR(name_node))) + return NULL; + } name = NEW_IDENTIFIER(name_node); if (!name) return NULL; @@ -2330,11 +2332,11 @@ alias_for_import_name(struct compiling *c, const node *n, int store) } else { node *asname_node = CHILD(n, 2); - alias_ty a = alias_for_import_name(c, CHILD(n, 0), store); + alias_ty a = alias_for_import_name(c, CHILD(n, 0), 0); if (!a) return NULL; assert(!a->asname); - if (store && !forbidden_check(c, asname_node, STR(asname_node))) + if (!forbidden_check(c, asname_node, STR(asname_node))) return NULL; a->asname = NEW_IDENTIFIER(asname_node); if (!a->asname) -- cgit v0.12