[pypy-issue] [issue937] No error if "from __future__" imports are not at beginning of file

Jared Sutton tracker at bugs.pypy.org
Wed Nov 23 21:52:26 CET 2011


New submission from Jared Sutton <jpsutton at gmail.com>:

If a "from __future__ import <some_feature>" line is added somewhere other than 
the top of the file, pypy does not report this as a problem.  It also doesn't 
seem to actually do the import.

Here's a test application showing the problem:

### BEGIN TEST PROGRAM
#!/usr/bin/env python2.7

import sys
from __future__ import print_function

def stderr (someString = ""):
  print(someString, file=sys.stderr)

stderr("test")
### END TEST PROGRAM

If the test program is executed using CPython 2.7, the following is output:

[ jsutton at jsutton-t61 ~/projects ]$ python2.7 test.py 
  File "test.py", line 4
    from __future__ import print_function
SyntaxError: from __future__ imports must occur at the beginning of the file

If the test program is executed with pypy 1.7, the following is output:

[ jsutton at jsutton-t61 ~/projects ]$ pypy test.py
Traceback (most recent call last):
  File "app_main.py", line 51, in run_toplevel
  File "test.py", line 7
    print(someString, file=sys.stderr)
                         ^
SyntaxError: invalid syntax

----------
messages: 3462
nosy: jpsutton, pypy-issue
priority: bug
status: unread
title: No error if "from __future__" imports are not at beginning of file

________________________________________
PyPy bug tracker <tracker at bugs.pypy.org>
<https://bugs.pypy.org/issue937>
________________________________________


More information about the pypy-issue mailing list