]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-38673: dont switch to ps2 if the line starts with comment or whitespace (GH-17421)
authorBatuhan Taşkaya <47358913+isidentical@users.noreply.github.com>
Mon, 9 Dec 2019 04:36:27 +0000 (07:36 +0300)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 9 Dec 2019 04:36:27 +0000 (20:36 -0800)
https://bugs.python.org/issue38673

Misc/NEWS.d/next/Core and Builtins/2019-12-01-00-17-44.bpo-38673.K_Tze-.rst [new file with mode: 0644]
Parser/tokenizer.c

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 (file)
index 0000000..8f8cf88
--- /dev/null
@@ -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.
index 5763e47c4b00b34bcc01d606ad34024edb28f4cb..f84093dae5b62ebe682c00df1614bb2ad641443b 100644 (file)
@@ -1148,6 +1148,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 */
             }