Skip to content

Commit 188d5ae

Browse files
miss-islingtonisidentical
authored andcommitted
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 109fc27) Co-authored-by: Batuhan Taşkaya <[email protected]>
1 parent b9f4b49 commit 188d5ae

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
@@ -1395,6 +1395,12 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end)
13951395
if (col == 0 && c == '\n' && tok->prompt != NULL) {
13961396
blankline = 0; /* Let it through */
13971397
}
1398+
else if (tok->prompt != NULL && tok->lineno == 1) {
1399+
/* In interactive mode, if the first line contains
1400+
only spaces and/or a comment, let it through. */
1401+
blankline = 0;
1402+
col = altcol = 0;
1403+
}
13981404
else {
13991405
blankline = 1; /* Ignore completely */
14001406
}

0 commit comments

Comments
 (0)