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

Incorrect error message for yield from #121657

Closed
JelleZijlstra opened this issue Jul 13, 2024 · 4 comments
Closed

Incorrect error message for yield from #121657

JelleZijlstra opened this issue Jul 13, 2024 · 4 comments
Labels
easy interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@JelleZijlstra
Copy link
Member

JelleZijlstra commented Jul 13, 2024

Bug report

Bug description:

% ./python.exe -c 'yield x'
  File "<string>", line 1
SyntaxError: 'yield' outside function
% ./python.exe -c 'yield from x'
  File "<string>", line 1
SyntaxError: 'yield' outside function
% ./python.exe -c 'async def f(): yield from x'
  File "<string>", line 1
SyntaxError: 'yield from' inside async function

The middle one should also say "yield from".

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

@JelleZijlstra JelleZijlstra added the type-bug An unexpected behavior, bug, or error label Jul 13, 2024
@JelleZijlstra JelleZijlstra self-assigned this Jul 13, 2024
@JelleZijlstra JelleZijlstra removed their assignment Jul 13, 2024
@JelleZijlstra
Copy link
Member Author

This is very easy to fix but I'll leave it for a bit in case a new contributor wants to get familiar with making a CPython change. Pointers for the fix:

  • The code to be changed is in compile.c, currently at line 6122 (search for "'yield' outside function" if it changes).
  • Tests should be added, probably around here Lib/test/test_generators.py:SyntaxError: 'yield' outside function. The existing test only tests yield, not yield from; we should add more tests.

@JelleZijlstra JelleZijlstra added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Jul 13, 2024
@serhiy-storchaka
Copy link
Member

I am not sure 5his should be fixed, as technically the error message is correct.

The error message in the third example is more specific because yield is valid here.

@gege-hoho
Copy link
Contributor

I will give it a try :)

gege-hoho added a commit to gege-hoho/cpython that referenced this issue Jul 13, 2024
encukou pushed a commit that referenced this issue Jul 13, 2024
…function (GH-121680)

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <[email protected]>
@encukou
Copy link
Member

encukou commented Jul 13, 2024

The existing message was technically correct, but yield from is definitely better.

gege-hoho added a commit to gege-hoho/cpython that referenced this issue Jul 13, 2024
gege-hoho added a commit to gege-hoho/cpython that referenced this issue Jul 13, 2024
gege-hoho added a commit to gege-hoho/cpython that referenced this issue Jul 13, 2024
Eclips4 pushed a commit to Eclips4/cpython that referenced this issue Jul 14, 2024
…outside of a function (pythonGH-121680)

(cherry picked from commit 178e44d)

Co-authored-by: Gregor <[email protected]>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <[email protected]>
ambv pushed a commit that referenced this issue Jul 15, 2024
GH-121768)

(cherry picked from commit 178e44d)

Co-authored-by: Gregor <[email protected]>
Co-authored-by: Bénédikt Tran <[email protected]>
ambv pushed a commit that referenced this issue Jul 15, 2024
GH-121769)

(cherry picked from commit 178e44d)

Co-authored-by: Gregor <[email protected]>
Co-authored-by: Bénédikt Tran <[email protected]>
gege-hoho added a commit to gege-hoho/cpython that referenced this issue Jul 16, 2024
estyxx pushed a commit to estyxx/cpython that referenced this issue Jul 17, 2024
… of a function (pythonGH-121680)

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jul 18, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jul 18, 2024
encukou pushed a commit that referenced this issue Jul 19, 2024
encukou pushed a commit that referenced this issue Jul 19, 2024
@encukou encukou closed this as completed Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants