mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
allow importing from a module named None if it has an 'as' clause
This commit is contained in:
parent
565e1b6bb7
commit
d1f5a59edb
2 changed files with 8 additions and 4 deletions
|
@ -281,6 +281,8 @@ if 1:
|
||||||
self.assertRaises(SyntaxError, compile, stmt, 'tmp', 'exec')
|
self.assertRaises(SyntaxError, compile, stmt, 'tmp', 'exec')
|
||||||
# This is ok.
|
# This is ok.
|
||||||
compile("from None import x", "tmp", "exec")
|
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):
|
def test_import(self):
|
||||||
succeed = [
|
succeed = [
|
||||||
|
|
|
@ -2316,8 +2316,10 @@ alias_for_import_name(struct compiling *c, const node *n, int store)
|
||||||
if (!str)
|
if (!str)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
if (!forbidden_check(c, name_node, STR(name_node)))
|
if (!forbidden_check(c, name_node, STR(name_node)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
name = NEW_IDENTIFIER(name_node);
|
name = NEW_IDENTIFIER(name_node);
|
||||||
if (!name)
|
if (!name)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -2330,11 +2332,11 @@ alias_for_import_name(struct compiling *c, const node *n, int store)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
node *asname_node = CHILD(n, 2);
|
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)
|
if (!a)
|
||||||
return NULL;
|
return NULL;
|
||||||
assert(!a->asname);
|
assert(!a->asname);
|
||||||
if (store && !forbidden_check(c, asname_node, STR(asname_node)))
|
if (!forbidden_check(c, asname_node, STR(asname_node)))
|
||||||
return NULL;
|
return NULL;
|
||||||
a->asname = NEW_IDENTIFIER(asname_node);
|
a->asname = NEW_IDENTIFIER(asname_node);
|
||||||
if (!a->asname)
|
if (!a->asname)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue