| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -218,6 +218,12 @@ def test_from_import(self): | |||
| 218 | 218 | im = ast.parse("from . import y").body[0] | |
| 219 | 219 | self.assertIsNone(im.module) | |
| 220 | 220 | ||
| 221 | + def test_non_interned_future_from_ast(self): | ||
| 222 | + mod = ast.parse("from __future__ import division") | ||
| 223 | + self.assertIsInstance(mod.body[0], ast.ImportFrom) | ||
| 224 | + mod.body[0].module = " __future__ ".strip() | ||
| 225 | + compile(mod, "<test>", "exec") | ||
| 226 | + | ||
| 221 | 227 | def test_base_classes(self): | |
| 222 | 228 | self.assertTrue(issubclass(ast.For, ast.stmt)) | |
| 223 | 229 | self.assertTrue(issubclass(ast.Name, ast.expr)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,9 @@ What's New in Python 3.2.4 | |||
| 10 | 10 | Core and Builtins | |
| 11 | 11 | ----------------- | |
| 12 | 12 | ||
| 13 | + - Issue #14378: Fix compiling ast.ImportFrom nodes with a "__future__" string as | ||
| 14 | + the module name that was not interned. | ||
| 15 | + | ||
| 13 | 16 | - Issue #14331: Use significantly less stack space when importing modules by | |
| 14 | 17 | allocating path buffers on the heap instead of the stack. | |
| 15 | 18 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,13 +60,6 @@ future_parse(PyFutureFeatures *ff, mod_ty mod, const char *filename) | |||
| 60 | 60 | { | |
| 61 | 61 | int i, found_docstring = 0, done = 0, prev_line = 0; | |
| 62 | 62 | ||
| 63 | - static PyObject *future; | ||
| 64 | - if (!future) { | ||
| 65 | - future = PyUnicode_InternFromString("__future__"); | ||
| 66 | - if (!future) | ||
| 67 | - return 0; | ||
| 68 | - } | ||
| 69 | - | ||
| 70 | 63 | if (!(mod->kind == Module_kind || mod->kind == Interactive_kind)) | |
| 71 | 64 | return 1; | |
| 72 | 65 | ||
@@ -93,7 +86,8 @@ future_parse(PyFutureFeatures *ff, mod_ty mod, const char *filename) | |||
| 93 | 86 | */ | |
| 94 | 87 | ||
| 95 | 88 | if (s->kind == ImportFrom_kind) { | |
| 96 | - if (s->v.ImportFrom.module == future) { | ||
| 89 | + PyObject *modname = s->v.ImportFrom.module; | ||
| 90 | + if (!PyUnicode_CompareWithASCIIString(modname, "__future__")) { | ||
| 97 | 91 | if (done) { | |
| 98 | 92 | PyErr_SetString(PyExc_SyntaxError, | |
| 99 | 93 | ERR_LATE_FUTURE); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments