cpython: f57cbcefde34 (original) (raw)
Mercurial > cpython
changeset 75868:f57cbcefde34 3.2
check by equality for __future__ not identity (closes #14378) [#14378]
Benjamin Peterson benjamin@python.org | |
---|---|
date | Thu, 22 Mar 2012 08:19:04 -0400 |
parents | 64f1b8ad9214 |
children | 9d793be3b4eb 1b467efb9b27 |
files | Lib/test/test_ast.py Misc/NEWS Python/future.c |
diffstat | 3 files changed, 11 insertions(+), 8 deletions(-)[+] [-] Lib/test/test_ast.py 6 Misc/NEWS 3 Python/future.c 10 |
line wrap: on
line diff
--- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -218,6 +218,12 @@ class AST_Tests(unittest.TestCase): 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")[](#l1.8)
self.assertIsInstance(mod.body[0], ast.ImportFrom)[](#l1.9)
mod.body[0].module = " __future__ ".strip()[](#l1.10)
compile(mod, "<test>", "exec")[](#l1.11)
+ def test_base_classes(self): self.assertTrue(issubclass(ast.For, ast.stmt)) self.assertTrue(issubclass(ast.Name, ast.expr))
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 3.2.4 Core and Builtins ----------------- +- Issue #14378: Fix compiling ast.ImportFrom nodes with a "future" string as
- Issue #14331: Use significantly less stack space when importing modules by allocating path buffers on the heap instead of the stack.
--- a/Python/future.c +++ b/Python/future.c @@ -60,13 +60,6 @@ future_parse(PyFutureFeatures *ff, mod_t { int i, found_docstring = 0, done = 0, prev_line = 0;
- static PyObject *future;
- if (!future) {
future = PyUnicode_InternFromString("__future__");[](#l3.9)
if (!future)[](#l3.10)
return 0;[](#l3.11)
- }
- if (!(mod->kind == Module_kind || mod->kind == Interactive_kind)) return 1; @@ -93,7 +86,8 @@ future_parse(PyFutureFeatures *ff, mod_t */ if (s->kind == ImportFrom_kind) {
if (s->v.ImportFrom.module == future) {[](#l3.21)
PyObject *modname = s->v.ImportFrom.module;[](#l3.22)
if (!PyUnicode_CompareWithASCIIString(modname, "__future__")) {[](#l3.23) if (done) {[](#l3.24) PyErr_SetString(PyExc_SyntaxError,[](#l3.25) ERR_LATE_FUTURE);[](#l3.26)