bpo-38673: dont switch to ps2 if the line starts with comment or whitespace (GH-17421) (GH-17522)

https://bugs.python.org/issue38673
(cherry picked from commit 109fc2792a)

Co-authored-by: Batuhan Taşkaya <47358913+isidentical@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2019-12-09 03:38:36 -08:00 committed by Ned Deily
parent b9f4b49c6e
commit 188d5ae6f0
2 changed files with 7 additions and 0 deletions

View File

@ -0,0 +1 @@
In REPL mode, don't switch to PS2 if the line starts with comment or whitespace. Based on work by Batuhan Taşkaya.

View File

@ -1395,6 +1395,12 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end)
if (col == 0 && c == '\n' && tok->prompt != NULL) {
blankline = 0; /* Let it through */
}
else if (tok->prompt != NULL && tok->lineno == 1) {
/* In interactive mode, if the first line contains
only spaces and/or a comment, let it through. */
blankline = 0;
col = altcol = 0;
}
else {
blankline = 1; /* Ignore completely */
}