You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Syntactically wrong suggestions by the new custom print statement error message #76209
print.py: Python file that suggests a wrong print call when run
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=Noneclosed_at=<Date2018-01-20.03:57:45.643>created_at=<Date2017-11-14.17:42:50.183>labels= ['interpreter-core', 'type-bug', '3.7']
title='Syntactically wrong suggestions by the new custom print statement error message'updated_at=<Date2018-01-20.03:57:45.641>user='https://github.com/mdraw'
When the following code is executed by Python 3.6.3 inside of a .py file:
deff():
print'%d'%2
, then Python gives the following error message:
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(int '%d' % 2)?
The "int" next to the left brace of the suggested print function is obviously wrong.
The expected message would be:
SyntaxError: Missing parentheses in call to 'print'. Did you mean print('%d' % 2)?
Using other values or "%s" in the formatted string in a print statement produces the same wrong message.
This bug only seems to happen when the print statement is inside of a function AND when it is is run inside of a .py file. At least I could not reproduce it in the python3 REPL or outside of a function.
I am attaching the minimal example file in this bug report. Running it with "$ python3 print.py" should show the mentioned bug.
Given the symptoms (stripping 4 spaces + "pr" from the start of the line, leaving "int " behind), it looks like we're not stripping the leading whitespace when determining the text to include in the suggested print() call.
To reproduce this at the REPL, you can use an if statement (first example uses a 4 space indent, the second uses an 8 space indent):
>>> if 1:
... print 123
File "<stdin>", line 2
print 123
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(int 123)?
>>> if 1:
... print 123
File "<stdin>", line 2
print 123
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(print 123)?
New changeset 4002d5d by Nick Coghlan (Miss Islington (bot)) in branch '3.6':
[3.6] bpo-32028: Fix suggestions for indented print statements (GH-5249) 4002d5d
Activity
mdraw commentedon Nov 14, 2017
I think I found a bug in the new print syntax suggestion introduced by https://bugs.python.org/issue30597.
When the following code is executed by Python 3.6.3 inside of a .py file:
, then Python gives the following error message:
The "int" next to the left brace of the suggested print function is obviously wrong.
The expected message would be:
Using other values or "%s" in the formatted string in a print statement produces the same wrong message.
This bug only seems to happen when the print statement is inside of a function AND when it is is run inside of a .py file. At least I could not reproduce it in the python3 REPL or outside of a function.
I am attaching the minimal example file in this bug report. Running it with "$ python3 print.py" should show the mentioned bug.
ncoghlan commentedon Nov 15, 2017
Given the symptoms (stripping 4 spaces + "pr" from the start of the line, leaving "int " behind), it looks like we're not stripping the leading whitespace when determining the text to include in the suggested print() call.
To reproduce this at the REPL, you can use an if statement (first example uses a 4 space indent, the second uses an 8 space indent):
CuriousLearner commentedon Nov 15, 2017
Sure, let me have a look at it and work on fix.
ncoghlan commentedon Jan 20, 2018
New changeset d57f26c by Nick Coghlan (Sanyam Khurana) in branch 'master':
bpo-32028: Fix suggestions for indented print statements (GH-4688)
d57f26c
ncoghlan commentedon Jan 20, 2018
New changeset 4002d5d by Nick Coghlan (Miss Islington (bot)) in branch '3.6':
[3.6] bpo-32028: Fix suggestions for indented print statements (GH-5249)
4002d5d
ncoghlan commentedon Jan 20, 2018
Thanks CuriousLearner for the PR and mdraw for the original issue report!