Terry J. Reedy <[email protected]> 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 <[email protected]>
<https://bugs.python.org/issue38673>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com