cpython: 1729ec440bb6 (original) (raw)
Mercurial > cpython
changeset 75872:1729ec440bb6 2.7
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 | 44a8385a8241 |
children | ad5e93ae22ef |
files | Lib/test/test_ast.py Misc/NEWS Python/future.c |
diffstat | 3 files changed, 12 insertions(+), 8 deletions(-)[+] [-] Lib/test/test_ast.py 6 Misc/NEWS 3 Python/future.c 11 |
line wrap: on
line diff
--- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -231,6 +231,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 @@ -9,6 +9,9 @@ What's New in Python 2.7.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 @@ -59,13 +59,6 @@ future_parse(PyFutureFeatures *ff, mod_t { int i, found_docstring = 0, done = 0, prev_line = 0;
- static PyObject *future;
- if (!future) {
future = PyString_InternFromString("__future__");[](#l3.9)
if (!future)[](#l3.10)
return 0;[](#l3.11)
- }
- if (!(mod->kind == Module_kind || mod->kind == Interactive_kind)) return 1; @@ -92,7 +85,9 @@ 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 (PyString_GET_SIZE(modname) == 10 &&[](#l3.23)
!strcmp(PyString_AS_STRING(modname), "__future__")) {[](#l3.24) if (done) {[](#l3.25) PyErr_SetString(PyExc_SyntaxError,[](#l3.26) ERR_LATE_FUTURE);[](#l3.27)