diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-12-09 03:38:36 -0800 |
---|---|---|
committer | Ned Deily <nad@python.org> | 2019-12-09 06:38:36 -0500 |
commit | 188d5ae6f047342f3d6860646ccf1a523ef8b0ed (patch) | |
tree | ed143ca0d19f226ebff0249c0f431d7eccc2cd22 | |
parent | b9f4b49c6e525afd6fce02cfc14be52e98a18f67 (diff) | |
download | cpython-git-188d5ae6f047342f3d6860646ccf1a523ef8b0ed.tar.gz |
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 109fc2792a490ee5cd8a423e17d415fbdedec5c8)
Co-authored-by: Batuhan Taşkaya <47358913+isidentical@users.noreply.github.com>
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2019-12-01-00-17-44.bpo-38673.K_Tze-.rst | 1 | ||||
-rw-r--r-- | Parser/tokenizer.c | 6 |
2 files changed, 7 insertions, 0 deletions
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 0000000000..8f8cf88e5e --- /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 d720f19eca..1739bb7ad5 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 */ } |