New submission from J. D. Bartlett <j...@bartletts.id.au>: GOAL I am trying to compile an AST which contains an ImportFrom node which performs a __future__ import. The ImportFrom node in question is the first node within the AST's body (as it should be, because __future__ imports must occur at the beginning of modules).
ISSUE Compiling the AST fails with the error "SyntaxError: from __future__ imports must occur at the beginning of the file". ANALYSIS The future_parse() function in future.c looks for __future__ imports and identifies them based on the condition (ds->v.ImportFrom.module == future) where future is constructed using PyString_InternFromString("__future__"). That is, the module attribute of the ImportFrom node is compared by identity with the interned string "__future__". The AST which I was compiling used the string "__future__" after extracting that string from a much longer string of user input, and as a result, the string was not interned. The attached file futureimport.py is a simple script demonstrating this issue. I have confirmed that the issue occurs in Python 2.7.2 and 3.2.2. ---------- components: Interpreter Core files: futureimport.py messages: 156477 nosy: talljosh priority: normal severity: normal status: open title: __future__ imports fail when compiling from python ast type: behavior versions: Python 2.7, Python 3.2 Added file: http://bugs.python.org/file24981/futureimport.py _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue14378> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com