Message287799
When you run the Python interpreter in interactive mode, get a sys.ps1 prompt (`...`), and type a comment-only or white-space-only line, the interpreter responds with a sys.ps2 prompt (`...`), instead of a sys.ps1 prompt. This seems wrong.
For example:
% ./python.exe
Python 3.7.0a0 (default, Feb 13 2017, 16:27:07)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> # comment-only <<-- line A
... <<-- line B
>>> <<-- line C
>>> <<-- line D
Line A is a comment-only line entered by the user. The interpreter responds with the sys.ps2 prompt (`...`), in line B. Line C is a null line (user enters only the Enter key, nothing else). The interpreter responds with a sys.ps1 prompt (`...`).
If user enters a white-space-only line at a sys.ps1 prompt, the interpreter responds the same as if it were a comment-only line, with a sys.ps2 prompt (line B).
The expected expected interpreter behaviour in response to a comment-only line or a white-space-only line, not in the midst of a compound statement, is that it be the same as to a null line, with a sys.ps1 prompt.
In the context of a compound statement, the expected interpreter behaviour is that a comment-only line or a white-space-only line continue the compound statement. Entering a null line in a compound statement ends the compound statement.
Another way to phrase it: the expected interpreter behaviour is that a comment-only line or white-space-only line not change the interpreter prompt: if it was sys.ps1, it remains so; if it was sys.ps2, it remains so.
I have reproduced this behaviour on my build of cpython 3.7.a0, python 3.6 from MacPorts, python 2.7 from MacPorts, all on Mac OS X. I see the same behaviour in the interactive shell at python.org/shell .
This makes me suspect that the Python design says my expectations are wrong. In that case, the current behaviour certainly is surprising. It should be documented. I haven't found such documentation yet. |
|
Date |
User |
Action |
Args |
2017-02-14 20:34:40 | JDLH | set | recipients:
+ JDLH |
2017-02-14 20:34:39 | JDLH | set | messageid: <1487104479.95.0.807901019481.issue29561@psf.upfronthosting.co.za> |
2017-02-14 20:34:39 | JDLH | link | issue29561 messages |
2017-02-14 20:34:38 | JDLH | create | |
|