Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

str literals, which are not docstrings, should not be allowed between __future__ imports #61636

Closed
Arfrever mannequin opened this issue Mar 16, 2013 · 4 comments
Closed
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@Arfrever
Copy link
Mannequin

Arfrever mannequin commented Mar 16, 2013

BPO 17434
Nosy @benjaminp

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2013-03-16.16:27:04.132>
created_at = <Date 2013-03-16.00:13:57.549>
labels = ['interpreter-core']
title = 'str literals, which are not docstrings, should not be allowed between __future__ imports'
updated_at = <Date 2013-03-16.16:28:15.870>
user = 'https://bugs.python.org/Arfrever'

bugs.python.org fields:

activity = <Date 2013-03-16.16:28:15.870>
actor = 'python-dev'
assignee = 'none'
closed = True
closed_date = <Date 2013-03-16.16:27:04.132>
closer = 'benjamin.peterson'
components = ['Interpreter Core']
creation = <Date 2013-03-16.00:13:57.549>
creator = 'Arfrever'
dependencies = []
files = []
hgrepos = []
issue_num = 17434
keywords = []
message_count = 4.0
messages = ['184277', '184287', '184328', '184329']
nosy_count = 3.0
nosy_names = ['benjamin.peterson', 'Arfrever', 'python-dev']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue17434'
versions = ['Python 2.7', 'Python 3.2', 'Python 3.3', 'Python 3.4']

@Arfrever
Copy link
Mannequin Author

Arfrever mannequin commented Mar 16, 2013

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
$

@Arfrever Arfrever mannequin added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Mar 16, 2013
@Arfrever
Copy link
Mannequin Author

Arfrever mannequin commented Mar 16, 2013

Jython and PyPy properly raise SyntaxError for test2.py.

@benjaminp
Copy link
Contributor

46cadd3955d0

@python-dev
Copy link
Mannequin

python-dev mannequin commented Mar 16, 2013

New changeset 46cadd3955d0 by Benjamin Peterson in branch 'default':
reject non-docs strings between future imports (closes bpo-17434)
http://hg.python.org/cpython/rev/46cadd3955d0

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)
Projects
None yet
Development

No branches or pull requests

1 participant