Skip to content

Commit ecf7b35

Browse files
committed
bpo-38673: dont switch to ps2 if the line starts with comment or whitespace
1 parent ded8888 commit ecf7b35

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
In REPL, dont switch to PS2 if the line starts with comment or whitespace.

Parser/tokenizer.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -874,8 +874,12 @@ tok_nextc(struct tok_state *tok)
874874
strcpy(newtok, buf);
875875
Py_DECREF(u);
876876
}
877-
if (tok->nextprompt != NULL)
878-
tok->prompt = tok->nextprompt;
877+
if (tok->nextprompt != NULL) {
878+
if (newtok != NULL && (*newtok == '#' || *newtok == ' ' || *newtok == '\t'))
879+
tok->nextprompt = NULL;
880+
else
881+
tok->prompt = tok->nextprompt;
882+
}
879883
if (newtok == NULL)
880884
tok->done = E_INTR;
881885
else if (*newtok == '\0') {
@@ -1399,7 +1403,8 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end)
13991403
/* Newline */
14001404
if (c == '\n') {
14011405
tok->atbol = 1;
1402-
if (blankline || tok->level > 0) {
1406+
if ((blankline || tok->level > 0) &&
1407+
!(tok->prompt != NULL && tok->nextprompt == NULL)) {
14031408
goto nextline;
14041409
}
14051410
*p_start = tok->start;

0 commit comments

Comments
 (0)