Issue 17434: str literals, which are not docstrings, should not be allowed between future imports (original) (raw)
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 $