GeezerVison is showing github.com — allow importing from a module named None if it has an 'as' clause · python/cpython@d1f5a59
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Lib/test/test_compile.py +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -281,6 +281,8 @@ def test_none_assignment(self): | 281 | 281 | self.assertRaises(SyntaxError, compile, stmt, 'tmp', 'exec') | 282 | 282 | # This is ok. | 283 | 283 | 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") | 284 | 286 |
| 285 | 287 | def test_import(self): | 286 | 288 | succeed = [ | |
Collapse file Copy file name to clipboardExpand all lines: Python/ast.c +6-4Lines changed: 6 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2316,8 +2316,10 @@ alias_for_import_name(struct compiling *c, const node *n, int store) | 2316 | 2316 | if (!str) | 2317 | 2317 | return NULL; | 2318 | 2318 | } | 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 | + } | 2321 | 2323 | name = NEW_IDENTIFIER(name_node); | 2322 | 2324 | if (!name) | 2323 | 2325 | return NULL; | @@ -2330,11 +2332,11 @@ alias_for_import_name(struct compiling *c, const node *n, int store) | 2330 | 2332 | } | 2331 | 2333 | else { | 2332 | 2334 | 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); | 2334 | 2336 | if (!a) | 2335 | 2337 | return NULL; | 2336 | 2338 | assert(!a->asname); | 2337 | | - if (store && !forbidden_check(c, asname_node, STR(asname_node))) | | 2339 | + if (!forbidden_check(c, asname_node, STR(asname_node))) | 2338 | 2340 | return NULL; | 2339 | 2341 | a->asname = NEW_IDENTIFIER(asname_node); | 2340 | 2342 | if (!a->asname) | |
|