Message156477
| Author |
talljosh |
| Recipients |
talljosh |
| Date |
2012年03月21日.06:19:41 |
| SpamBayes Score |
0.00011334349 |
| Marked as misclassified |
No |
| Message-id |
<1332310782.47.0.882635712321.issue14378@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2012年03月21日 06:19:42 | talljosh | set | recipients:
+ talljosh |
| 2012年03月21日 06:19:42 | talljosh | set | messageid: <1332310782.47.0.882635712321.issue14378@psf.upfronthosting.co.za> |
| 2012年03月21日 06:19:41 | talljosh | link | issue14378 messages |
| 2012年03月21日 06:19:41 | talljosh | create |
|