[pypy-issue] Issue #2526: Future statements are considered illegal if they are separated by a semicolon (pypy/pypy)
Nurdok
issues-reply at bitbucket.org
Thu Mar 30 06:29:55 EDT 2017
New issue 2526: Future statements are considered illegal if they are separated by a semicolon
https://bitbucket.org/pypy/pypy/issues/2526/future-statements-are-considered-illegal
Nurdok:
According to the Python documentation:
> A future statement must appear near the top of the module.
And indeed, both `CPython` and PyPy emit an error when violating this rule:
```
#!python
# foo.py
import sys
from __future__ import unicode_literals
from __future__ import nested_scopes
```
```
#!bash
$ python foo.py
File "foo.py", line 2
from __future__ import unicode_literals
^
SyntaxError: from __future__ imports must occur at the beginning of the file
```
```
#!bash
$ python foo.py
$ pypy foo.py
File "foo.py", line 2
SyntaxError: __future__ statements must appear at beginning of file
```
When you remove the `import sys` line, both `CPython` and `PyPy` accept the program. However, when you change `foo.py` to perform both statements in the same line:
```
#!python
# foo.py
from __future__ import unicode_literals; from __future__ import nested_scopes
```
`CPython` accepts the program, while `PyPy` does not:
```
#!bash
$ pypy foo.py
File "foo.py", line 1
SyntaxError: __future__ statements must appear at beginning of file
```
Tested on `CPython` 2.7.12 and:
```
#!bash
$ pypy -V
Python 2.7.13 (fa3249d55d15, Mar 20 2017, 03:48:52)
[PyPy 5.7.0 with MSC v.1500 32 bit]
```
More information about the pypy-issue
mailing list