(original) (raw)
changeset: 75868:f57cbcefde34 branch: 3.2 parent: 75859:64f1b8ad9214 user: Benjamin Peterson benjamin@python.org date: Thu Mar 22 08:19:04 2012 -0400 files: Lib/test/test_ast.py Misc/NEWS Python/future.c description: check by equality for __future__ not identity (closes #14378) diff -r 64f1b8ad9214 -r f57cbcefde34 Lib/test/test_ast.py --- a/Lib/test/test_ast.py Wed Mar 21 14:53:42 2012 -0400 +++ b/Lib/test/test_ast.py Thu Mar 22 08:19:04 2012 -0400 @@ -218,6 +218,12 @@ im = ast.parse("from . import y").body[0] self.assertIsNone(im.module) + def test_non_interned_future_from_ast(self): + mod = ast.parse("from __future__ import division") + self.assertIsInstance(mod.body[0], ast.ImportFrom) + mod.body[0].module = " __future__ ".strip() + compile(mod, "", "exec") + def test_base_classes(self): self.assertTrue(issubclass(ast.For, ast.stmt)) self.assertTrue(issubclass(ast.Name, ast.expr)) diff -r 64f1b8ad9214 -r f57cbcefde34 Misc/NEWS --- a/Misc/NEWS Wed Mar 21 14:53:42 2012 -0400 +++ b/Misc/NEWS Thu Mar 22 08:19:04 2012 -0400 @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #14378: Fix compiling ast.ImportFrom nodes with a "__future__" string as + the module name that was not interned. + - Issue #14331: Use significantly less stack space when importing modules by allocating path buffers on the heap instead of the stack. diff -r 64f1b8ad9214 -r f57cbcefde34 Python/future.c --- a/Python/future.c Wed Mar 21 14:53:42 2012 -0400 +++ b/Python/future.c Thu Mar 22 08:19:04 2012 -0400 @@ -60,13 +60,6 @@ { int i, found_docstring = 0, done = 0, prev_line = 0; - static PyObject *future; - if (!future) { - future = PyUnicode_InternFromString("__future__"); - if (!future) - return 0; - } - if (!(mod->kind == Module_kind || mod->kind == Interactive_kind)) return 1; @@ -93,7 +86,8 @@ */ if (s->kind == ImportFrom_kind) { - if (s->v.ImportFrom.module == future) { + PyObject *modname = s->v.ImportFrom.module; + if (!PyUnicode_CompareWithASCIIString(modname, "__future__")) { if (done) { PyErr_SetString(PyExc_SyntaxError, ERR_LATE_FUTURE);/benjamin@python.org