classification
Title: str literals, which are not docstrings, should not be allowed between __future__ imports
Type: Stage: committed/rejected
Components: Interpreter Core Versions: Python 3.4, Python 3.3, Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, benjamin.peterson, python-dev
Priority: normal Keywords:

Created on 2013-03-16 00:13 by Arfrever, last changed 2013-03-16 16:28 by python-dev. This issue is now closed.

Messages (4)
msg184277 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * Date: 2013-03-16 00:13
test1.py shows that a str literal before first import from __future__ is a docstring.
test2.py shows that a str literal after first import from __future__ is not a docstring.
test2.py shows that if docstring is absent, then a single str literal between imports from __future__ does not cause SyntaxError, while it should.
test3.py shows that if docstring is present, then a str literal between imports from __future__ causes SyntaxError.
test4.py shows that if docstring is absent, then >=2 str literals between imports from __future__ cause SyntaxError.

$ cat test1.py
"some text"
from __future__ import absolute_import
print(__doc__)
$ cat test2.py
from __future__ import absolute_import
"some text"
from __future__ import print_function
print(__doc__)
$ cat test3.py
"some text 1"
from __future__ import absolute_import
"some text 2"
from __future__ import print_function
$ cat test4.py
from __future__ import absolute_import
"some text 1"
"some text 2"
from __future__ import print_function
$ python3.4 test1.py
some text
$ python3.4 test2.py
None
$ python3.4 test3.py
  File "test3.py", line 4
    from __future__ import print_function
    ^
SyntaxError: from __future__ imports must occur at the beginning of the file
$ python3.4 test4.py
  File "test4.py", line 4
    from __future__ import print_function
    ^
SyntaxError: from __future__ imports must occur at the beginning of the file
$
msg184287 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * Date: 2013-03-16 02:58
Jython and PyPy properly raise SyntaxError for test2.py.
msg184328 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2013-03-16 16:27
46cadd3955d0
msg184329 - (view) Author: Roundup Robot (python-dev) Date: 2013-03-16 16:28
New changeset 46cadd3955d0 by Benjamin Peterson in branch 'default':
reject non-docs strings between future imports (closes #17434)
http://hg.python.org/cpython/rev/46cadd3955d0
History
Date User Action Args
2013-03-16 16:28:15python-devsetnosy: + python-dev

messages: + msg184329
stage: committed/rejected
2013-03-16 16:27:04benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg184328

resolution: fixed
2013-03-16 02:58:13Arfreversetmessages: + msg184287
2013-03-16 00:13:57Arfrevercreate