[Python-checkins] bpo-43823: Fix location of one of the errors for invalid dictionary literals (GH-25427)

pablogsal webhook-mailer at python.org
Thu Apr 15 19:45:52 EDT 2021


https://github.com/python/cpython/commit/b5b98bd8f8c72a9068cf149dbc162c8c95d30057
commit: b5b98bd8f8c72a9068cf149dbc162c8c95d30057
branch: master
author: Pablo Galindo <Pablogsal at gmail.com>
committer: pablogsal <Pablogsal at gmail.com>
date: 2021-04-16T00:45:42+01:00
summary:

bpo-43823: Fix location of one of the errors for invalid dictionary literals (GH-25427)

files:
M Grammar/python.gram
M Parser/parser.c

diff --git a/Grammar/python.gram b/Grammar/python.gram
index e5baac3663675..d91e887e04dc0 100644
--- a/Grammar/python.gram
+++ b/Grammar/python.gram
@@ -899,6 +899,7 @@ invalid_double_starred_kvpairs:
     | expression ':' a='*' bitwise_or { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot use a starred expression in a dictionary value") }
     | expression a=':' &('}'|',') { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "expression expected after dictionary key and ':'") }
 invalid_kvpair:
-    | a=expression !(':') { RAISE_SYNTAX_ERROR("':' expected after dictionary key") }
+    | a=expression !(':') {
+        RAISE_ERROR_KNOWN_LOCATION(p, PyExc_SyntaxError, a->lineno, a->end_col_offset - 1, "':' expected after dictionary key") }
     | expression ':' a='*' bitwise_or { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot use a starred expression in a dictionary value") }
     | expression a=':' {RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "expression expected after dictionary key and ':'") }
diff --git a/Parser/parser.c b/Parser/parser.c
index 2f7a71a5418e6..e47093e1dca7d 100644
--- a/Parser/parser.c
+++ b/Parser/parser.c
@@ -19379,7 +19379,7 @@ invalid_kvpair_rule(Parser *p)
         )
         {
             D(fprintf(stderr, "%*c+ invalid_kvpair[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression !(':')"));
-            _res = RAISE_SYNTAX_ERROR ( "':' expected after dictionary key" );
+            _res = RAISE_ERROR_KNOWN_LOCATION ( p , PyExc_SyntaxError , a -> lineno , a -> end_col_offset - 1 , "':' expected after dictionary key" );
             if (_res == NULL && PyErr_Occurred()) {
                 p->error_indicator = 1;
                 D(p->level--);



More information about the Python-checkins mailing list