You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A SyntaxError less detailed since 3.10 in specific example #94192
New SyntaxError ^ pointer is misleading in following example compared to older python versions.
d = {
"foo":"foo",
"bar":lambda b:{"bar":testfn(von="1"b=b)},
}
Results in error message on 3.10.5:
File "test.py", line 3
"bar":lambda b:{"bar":testfn(von="1"b=b)},
^
SyntaxError: expression expected after dictionary key and ':'
While on python 3.8 it was more helpful:
File "test.py", line 3
"bar":lambda b:{"bar":testfn(von="1"b=b)},
^
SyntaxError: invalid syntax
edit: added triple backquotes to preserve formatting on github. thanks hauntsaninja.
On 3.10.5 it is pointing on the ":" prior to lambda, while on 3.8 it is pointing on the missing comma.
You can use triple backquotes (```) to preserve formatting on Github.
λ python3.9
Python 3.9.12 (main, Apr 16 2022, 17:49:09)
[Clang 13.0.0 (clang-1300.0.27.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> d = { "foo":"foo", "bar":lambda b:{"bar":testfn(von="1"b=b)}, }
File "<stdin>", line 1
d = { "foo":"foo", "bar":lambda b:{"bar":testfn(von="1"b=b)}, }
^
SyntaxError: invalid syntax
λ python3.10
Python 3.10.5 (main, Jun 18 2022, 23:46:13) [Clang 13.0.0 (clang-1300.0.27.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> d = { "foo":"foo", "bar":lambda b:{"bar":testfn(von="1"b=b)}, }
File "<stdin>", line 1
d = { "foo":"foo", "bar":lambda b:{"bar":testfn(von="1"b=b)}, }
^
SyntaxError: expression expected after dictionary key and ':'
Activity
hauntsaninja commentedon Jun 24, 2022
You can use triple backquotes (```) to preserve formatting on Github.
iritkatriel commentedon Jun 26, 2022
cc @pablogsal
wookie184 commentedon Jun 26, 2022
I think i've found a simple fix that seems to work, will open a PR.
gh-94192: Fix error for dictionary literals with invalid expression a…
pythongh-94192: Fix error for dictionary literals with invalid expres…
gh-94192: Fix error for dictionary literals with invalid expression a…
[3.10] gh-94192: Fix error for dictionary literals with invalid expre…