GeezerVison is showing github.com — bpo-44368: Ensure we don't raise incorrect custom syntax errors with … · python/cpython@457ce60
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Lib/test/test_exceptions.py +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -215,6 +215,7 @@ def testSyntaxErrorOffset(self): | 215 | 215 | check('[\nfile\nfor str(file)\nin\n[]\n]', 3, 5) | 216 | 216 | check('[file for\n str(file) in []]', 2, 2) | 217 | 217 | check("ages = {'Alice'=22, 'Bob'=23}", 1, 16) | | 218 | + check('match ...:\n case {**rest, "key": value}:\n ...', 2, 19) | 218 | 219 |
| 219 | 220 | # Errors thrown by compile.c | 220 | 221 | check('class foo:return 1', 1, 11) | |
Collapse file Copy file name to clipboardExpand all lines: Lib/test/test_syntax.py +19-1Lines changed: 19 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 267 | 267 | SyntaxError: invalid syntax. Perhaps you forgot a comma? | 268 | 268 |
| 269 | 269 | # Make sure soft keywords constructs don't raise specialized | 270 | | -# errors regarding missing commas | | 270 | +# errors regarding missing commas or other spezialiced errors | 271 | 271 |
| 272 | 272 | >>> match x: | 273 | 273 | ... y = 3 | | 280 | 280 | Traceback (most recent call last): | 281 | 281 | SyntaxError: invalid syntax | 282 | 282 |
| | 283 | +>>> match x: | | 284 | +... case $: | | 285 | +... ... | | 286 | +Traceback (most recent call last): | | 287 | +SyntaxError: invalid syntax | | 288 | +
| | 289 | +>>> match ...: | | 290 | +... case {**rest, "key": value}: | | 291 | +... ... | | 292 | +Traceback (most recent call last): | | 293 | +SyntaxError: invalid syntax | | 294 | +
| | 295 | +>>> match ...: | | 296 | +... case {**_}: | | 297 | +... ... | | 298 | +Traceback (most recent call last): | | 299 | +SyntaxError: invalid syntax | | 300 | +
| 283 | 301 | From compiler_complex_args(): | 284 | 302 |
| 285 | 303 | >>> def f(None=1): | |
Collapse file Copy file name to clipboardExpand all lines: Parser/pegen.c +11-4Lines changed: 11 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -936,10 +936,9 @@ _PyPegen_get_last_nonnwhitespace_token(Parser *p) | 936 | 936 | return token; | 937 | 937 | } | 938 | 938 |
| 939 | | -expr_ty | 940 | | -_PyPegen_name_token(Parser *p) | | 939 | +static expr_ty | | 940 | +_PyPegen_name_from_token(Parser *p, Token* t) | 941 | 941 | { | 942 | | - Token *t = _PyPegen_expect_token(p, NAME); | 943 | 942 | if (t == NULL) { | 944 | 943 | return NULL; | 945 | 944 | } | @@ -957,6 +956,14 @@ _PyPegen_name_token(Parser *p) | 957 | 956 | t->end_col_offset, p->arena); | 958 | 957 | } | 959 | 958 |
| | 959 | + | | 960 | +expr_ty | | 961 | +_PyPegen_name_token(Parser *p) | | 962 | +{ | | 963 | + Token *t = _PyPegen_expect_token(p, NAME); | | 964 | + return _PyPegen_name_from_token(p, t); | | 965 | +} | | 966 | + | 960 | 967 | void * | 961 | 968 | _PyPegen_string_token(Parser *p) | 962 | 969 | { | @@ -974,7 +981,7 @@ expr_ty _PyPegen_soft_keyword_token(Parser *p) { | 974 | 981 | PyBytes_AsStringAndSize(t->bytes, &the_token, &size); | 975 | 982 | for (char **keyword = p->soft_keywords; *keyword != NULL; keyword++) { | 976 | 983 | if (strncmp(*keyword, the_token, size) == 0) { | 977 | | - return _PyPegen_name_token(p); | | 984 | + return _PyPegen_name_from_token(p, t); | 978 | 985 | } | 979 | 986 | } | 980 | 987 | return NULL; | |
|