From 0ef5a7f0cf52e7e84f6ebde35014c8094c314baf Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Sun, 8 Dec 2019 20:56:19 -0800 Subject: [PATCH] bpo-38673: dont switch to ps2 if the line starts with comment or whitespace (GH-17421) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://bugs.python.org/issue38673 (cherry picked from commit 109fc2792a490ee5cd8a423e17d415fbdedec5c8) Co-authored-by: Batuhan Taşkaya <47358913+isidentical@users.noreply.github.com> (cherry picked from commit 184a3812b81e2f7d4bc6453bf7ceabe8ac590202) Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> --- .../2019-12-01-00-17-44.bpo-38673.K_Tze-.rst | 1 + Parser/tokenizer.c | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2019-12-01-00-17-44.bpo-38673.K_Tze-.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-12-01-00-17-44.bpo-38673.K_Tze-.rst b/Misc/NEWS.d/next/Core and Builtins/2019-12-01-00-17-44.bpo-38673.K_Tze-.rst new file mode 100644 index 00000000000000..8f8cf88e5e2103 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2019-12-01-00-17-44.bpo-38673.K_Tze-.rst @@ -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. diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index d720f19eca9db8..1739bb7ad55650 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -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 */ }