Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A SyntaxError less detailed since 3.10 in specific example #94192

Closed
Serpens66 opened this issue Jun 24, 2022 · 3 comments · Fixed by #94304
Closed

A SyntaxError less detailed since 3.10 in specific example #94192

Serpens66 opened this issue Jun 24, 2022 · 3 comments · Fixed by #94304
Labels
interpreter-core type-bug

Comments

@Serpens66
Copy link

@Serpens66 Serpens66 commented Jun 24, 2022

Python 3.10.5

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.

@Serpens66 Serpens66 added the type-bug label Jun 24, 2022
@AlexWaygood AlexWaygood added the interpreter-core label Jun 24, 2022
@hauntsaninja
Copy link
Contributor

@hauntsaninja hauntsaninja commented Jun 24, 2022

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 ':'

@iritkatriel
Copy link
Member

@iritkatriel iritkatriel commented Jun 26, 2022

cc @pablogsal

@wookie184
Copy link
Contributor

@wookie184 wookie184 commented Jun 26, 2022

I think i've found a simple fix that seems to work, will open a PR.

pablogsal pushed a commit that referenced this issue Jun 26, 2022
…s value. (#94304)

* Fix error for dictionary literals with invalid expression as value.

* Remove trailing whitespace
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 26, 2022
…sion as value. (pythonGH-94304)

* Fix error for dictionary literals with invalid expression as value.

* Remove trailing whitespace
(cherry picked from commit 8c237a7)

Co-authored-by: wookie184 <wookie1840@gmail.com>
miss-islington added a commit that referenced this issue Jun 26, 2022
…s value. (GH-94304)

* Fix error for dictionary literals with invalid expression as value.

* Remove trailing whitespace
(cherry picked from commit 8c237a7)

Co-authored-by: wookie184 <wookie1840@gmail.com>
wookie184 added a commit to wookie184/cpython that referenced this issue Jun 26, 2022
… expression as value. (pythonGH-94304)

* Fix error for dictionary literals with invalid expression as value.

* Remove trailing whitespace.
(cherry picked from commit 8c237a7)

Co-authored-by: wookie184 <wookie1840@gmail.com>
wookie184 added a commit to wookie184/cpython that referenced this issue Jun 27, 2022
… expression as value. (pythonGH-94304)

* Fix error for dictionary literals with invalid expression as value.

* Remove trailing whitespace.
(cherry picked from commit 8c237a7)

Co-authored-by: wookie184 <wookie1840@gmail.com>
pablogsal pushed a commit that referenced this issue Jun 27, 2022
…ssion as value. (GH-94304) (#94344)

Co-authored-by: wookie184 <wookie1840@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants