Skip to content

Commit 184a381

Browse files
bpo-38673: dont switch to ps2 if the line starts with comment or whitespace (GH-17421)
https://bugs.python.org/issue38673 (cherry picked from commit 109fc27) Co-authored-by: Batuhan Taşkaya <[email protected]>
1 parent 2abd3a8 commit 184a381

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
In REPL mode, don't switch to PS2 if the line starts with comment or whitespace. Based on work by Batuhan Taşkaya.

Parser/tokenizer.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,12 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end)
11481148
if (col == 0 && c == '\n' && tok->prompt != NULL) {
11491149
blankline = 0; /* Let it through */
11501150
}
1151+
else if (tok->prompt != NULL && tok->lineno == 1) {
1152+
/* In interactive mode, if the first line contains
1153+
only spaces and/or a comment, let it through. */
1154+
blankline = 0;
1155+
col = altcol = 0;
1156+
}
11511157
else {
11521158
blankline = 1; /* Ignore completely */
11531159
}

0 commit comments

Comments
 (0)