File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed
Misc/NEWS.d/next/Core and Builtins Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -2145,6 +2145,22 @@ def test_error_parenthesis(self):
21452145 for paren in ")]}" :
21462146 self ._check_error (paren + "1 + 2" , f"unmatched '\\ { paren } '" )
21472147
2148+ # Some more complex examples:
2149+ code = """\
2150+ func(
2151+ a=["unclosed], # Need a quote in this comment: "
2152+ b=2,
2153+ )
2154+ """
2155+ self ._check_error (code , "parenthesis '\\ )' does not match opening parenthesis '\\ ['" )
2156+
2157+ def test_error_string_literal (self ):
2158+
2159+ self ._check_error ("'blech" , "unterminated string literal" )
2160+ self ._check_error ('"blech' , "unterminated string literal" )
2161+ self ._check_error ("'''blech" , "unterminated triple-quoted string literal" )
2162+ self ._check_error ('"""blech' , "unterminated triple-quoted string literal" )
2163+
21482164 def test_invisible_characters (self ):
21492165 self ._check_error ('print\x17 ("Hello")' , "invalid non-printable character" )
21502166
Original file line number Diff line number Diff line change 1+ Honor existing errors obtained when searching for mismatching parentheses in
2+ the tokenizer. Patch by Pablo Galindo
Original file line number Diff line number Diff line change @@ -169,6 +169,10 @@ _PyPegen_tokenize_full_source_to_check_for_errors(Parser *p) {
169169 for (;;) {
170170 switch (_PyTokenizer_Get (p -> tok , & new_token )) {
171171 case ERRORTOKEN :
172+ if (PyErr_Occurred ()) {
173+ ret = -1 ;
174+ goto exit ;
175+ }
172176 if (p -> tok -> level != 0 ) {
173177 int error_lineno = p -> tok -> parenlinenostack [p -> tok -> level - 1 ];
174178 if (current_err_line > error_lineno ) {
You can’t perform that action at this time.
0 commit comments