File tree Expand file tree Collapse file tree
Misc/NEWS.d/next/Core and Builtins Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -504,6 +504,7 @@ def test_single_statement(self):
504504 self .compile_single ("if x:\n f(x)" )
505505 self .compile_single ("if x:\n f(x)\n else:\n g(x)" )
506506 self .compile_single ("class T:\n pass" )
507+ self .compile_single ("c = '''\n a=1\n b=2\n c=3\n '''" )
507508
508509 def test_bad_single_statement (self ):
509510 self .assertInvalidSingle ('1\n 2' )
@@ -514,6 +515,7 @@ def test_bad_single_statement(self):
514515 self .assertInvalidSingle ('f()\n # blah\n blah()' )
515516 self .assertInvalidSingle ('f()\n xy # blah\n blah()' )
516517 self .assertInvalidSingle ('x = 5 # comment\n x = 6\n ' )
518+ self .assertInvalidSingle ("c = '''\n d=1\n '''\n a = 1\n \n b = 2\n " )
517519
518520 def test_particularly_evil_undecodable (self ):
519521 # Issue 24022
Original file line number Diff line number Diff line change 1+ Fix bug where the built-in :func: `compile ` function did not always raise a
2+ :exc: `SyntaxError ` when passed multiple statements in 'single' mode. Patch by
3+ Weipeng Hong.
Original file line number Diff line number Diff line change @@ -675,31 +675,13 @@ _PyPegen_number_token(Parser *p)
675675 t -> end_col_offset , p -> arena );
676676}
677677
678- static int // bool
679- newline_in_string (Parser * p , const char * cur )
680- {
681- for (const char * c = cur ; c >= p -> tok -> buf ; c -- ) {
682- if (* c == '\'' || * c == '"' ) {
683- return 1 ;
684- }
685- }
686- return 0 ;
687- }
688-
689678/* Check that the source for a single input statement really is a single
690679 statement by looking at what is left in the buffer after parsing.
691680 Trailing whitespace and comments are OK. */
692681static int // bool
693682bad_single_statement (Parser * p )
694683{
695- const char * cur = strchr (p -> tok -> buf , '\n' );
696-
697- /* Newlines are allowed if preceded by a line continuation character
698- or if they appear inside a string. */
699- if (!cur || (cur != p -> tok -> buf && * (cur - 1 ) == '\\' )
700- || newline_in_string (p , cur )) {
701- return 0 ;
702- }
684+ char * cur = p -> tok -> cur ;
703685 char c = * cur ;
704686
705687 for (;;) {
You can’t perform that action at this time.
0 commit comments