File tree Expand file tree Collapse file tree 3 files changed +23
-0
lines changed
Misc/NEWS.d/next/Core and Builtins Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -2145,6 +2145,23 @@ def test_error_parenthesis(self):
2145
2145
for paren in ")]}" :
2146
2146
self ._check_error (paren + "1 + 2" , f"unmatched '\\ { paren } '" )
2147
2147
2148
+ def test_error_string_literal (self ):
2149
+
2150
+ self ._check_error ("'blech" , "unterminated string literal" )
2151
+ self ._check_error ('"blech' , "unterminated string literal" )
2152
+ self ._check_error ("'''blech" , "unterminated triple-quoted string literal" )
2153
+ self ._check_error ('"""blech' , "unterminated triple-quoted string literal" )
2154
+
2155
+
2156
+ # Some more complex examples:
2157
+ code = """\
2158
+ func(
2159
+ a=["unclosed], # Need a quote in this comment: "
2160
+ b=2,
2161
+ )
2162
+ """
2163
+ self ._check_error (code , "does not match" )
2164
+
2148
2165
def test_invisible_characters (self ):
2149
2166
self ._check_error ('print\x17 ("Hello")' , "invalid non-printable character" )
2150
2167
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