Skip to content

Commit d1f5a59

Browse files
committed
allow importing from a module named None if it has an 'as' clause
1 parent 565e1b6 commit d1f5a59

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Lib/test/test_compile.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ def test_none_assignment(self):
281281
self.assertRaises(SyntaxError, compile, stmt, 'tmp', 'exec')
282282
# This is ok.
283283
compile("from None import x", "tmp", "exec")
284+
compile("from x import None as y", "tmp", "exec")
285+
compile("import None as x", "tmp", "exec")
284286

285287
def test_import(self):
286288
succeed = [

Python/ast.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,8 +2316,10 @@ alias_for_import_name(struct compiling *c, const node *n, int store)
23162316
if (!str)
23172317
return NULL;
23182318
}
2319-
if (!forbidden_check(c, name_node, STR(name_node)))
2320-
return NULL;
2319+
else {
2320+
if (!forbidden_check(c, name_node, STR(name_node)))
2321+
return NULL;
2322+
}
23212323
name = NEW_IDENTIFIER(name_node);
23222324
if (!name)
23232325
return NULL;
@@ -2330,11 +2332,11 @@ alias_for_import_name(struct compiling *c, const node *n, int store)
23302332
}
23312333
else {
23322334
node *asname_node = CHILD(n, 2);
2333-
alias_ty a = alias_for_import_name(c, CHILD(n, 0), store);
2335+
alias_ty a = alias_for_import_name(c, CHILD(n, 0), 0);
23342336
if (!a)
23352337
return NULL;
23362338
assert(!a->asname);
2337-
if (store && !forbidden_check(c, asname_node, STR(asname_node)))
2339+
if (!forbidden_check(c, asname_node, STR(asname_node)))
23382340
return NULL;
23392341
a->asname = NEW_IDENTIFIER(asname_node);
23402342
if (!a->asname)

0 commit comments

Comments
 (0)