[issue38673] REPL shows continuation prompt (...) when comment or space entered
Terry J. Reedy
report at bugs.python.org
Fri Nov 8 17:55:09 EST 2019
Terry J. Reedy <tjreedy at udel.edu> added the comment:
Entering 'pass' or a completely blank line results in a new primary prompt, at least on Windows. The Windows REPL otherwise prints ... even for effectively blank lines. IDLE usually prints a new prompt for effectively blank lines.
>>>
>>> #a
>>> # a
>>> #a
>>>
I agree that these look better. This behavior comes from code.InteractiveInterpreter and ultimately codeop.
def _maybe_compile(compiler, source, filename, symbol):
# Check for source consisting of only blank lines and comments
for line in source.split("\n"):
line = line.strip()
if line and line[0] != '#':
break # Leave it alone
else:
if symbol != "eval":
source = "pass" # Replace it with a 'pass' statement
As noted above, 'pass\n' is treated the same as '\n'
The first line above originally had a space, but IDLE appears to strip trailing whitespace also, even outside of comments. (For an ending '\ ', this prevents SyntaxError, but maybe this is a bad lesson for beginners.) However, I did find a case with an unnecessary continuation line.
>>> # a
>>>
This puzzles me, as it should be treated exactly the same as without the space after '#'. ast.dump(ast.parse(' # a\n', '', 'single')) gives the same result, 'Module(body=[], type_ignores=[])', as without.
----------
nosy: +terry.reedy
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38673>
_______________________________________
More information about the Python-bugs-list
mailing list