File tree 3 files changed +22
-0
lines changed
Misc/NEWS.d/next/Core and Builtins
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):
2145
2145
for paren in ")]}" :
2146
2146
self ._check_error (paren + "1 + 2" , f"unmatched '\\ { paren } '" )
2147
2147
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
+
2148
2164
def test_invisible_characters (self ):
2149
2165
self ._check_error ('print\x17 ("Hello")' , "invalid non-printable character" )
2150
2166
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) {
169
169
for (;;) {
170
170
switch (_PyTokenizer_Get (p -> tok , & new_token )) {
171
171
case ERRORTOKEN :
172
+ if (PyErr_Occurred ()) {
173
+ ret = -1 ;
174
+ goto exit ;
175
+ }
172
176
if (p -> tok -> level != 0 ) {
173
177
int error_lineno = p -> tok -> parenlinenostack [p -> tok -> level - 1 ];
174
178
if (current_err_line > error_lineno ) {
You can’t perform that action at this time.
0 commit comments