mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
Issue #12705: Raise SyntaxError when compiling multiple statements as single interactive statement
This commit is contained in:
parent
00c7f85298
commit
fa21bf015d
5 changed files with 52 additions and 0 deletions
|
|
@ -224,6 +224,23 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
|
|||
if (err_ret->error == E_DONE) {
|
||||
n = ps->p_tree;
|
||||
ps->p_tree = NULL;
|
||||
|
||||
/* Check that the source for a single input statement really
|
||||
is a single statement by looking at what is left in the
|
||||
buffer after parsing. Trailing whitespace and comments
|
||||
are OK. */
|
||||
if (start == single_input) {
|
||||
char *cur = tok->cur;
|
||||
char c = *tok->cur;
|
||||
|
||||
while (c == ' ' || c == '\t' || c == '\n' || c == '\014')
|
||||
c = *++cur;
|
||||
|
||||
if (c && c != '#') {
|
||||
err_ret->error = E_BADSINGLE;
|
||||
n = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
n = NULL;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue