Skip to content

Incorrect error message for yield from #121657

Closed

Description

@JelleZijlstra

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

Activity

  1. removed their assignment
    on Jul 13, 2024
  2. JelleZijlstra commented on Jul 13, 2024

    @JelleZijlstra
    MemberAuthor

    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.
  3. serhiy-storchaka commented on Jul 13, 2024

    @serhiy-storchaka
    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.

  4. gege-hoho commented on Jul 13, 2024

    @gege-hoho
    Contributor

    I will give it a try :)

  5. added a commit that references this issue on Jul 13, 2024
  6. added a commit that references this issue on Jul 13, 2024
  7. encukou commented on Jul 13, 2024

    @encukou
    Member

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

  8. added 3 commits that reference this issue on Jul 13, 2024
  9. added a commit that references this issue on Jul 14, 2024
  10. added 2 commits that reference this issue on Jul 15, 2024
  11. added a commit that references this issue on Jul 16, 2024
  12. added a commit that references this issue on Jul 17, 2024
  13. added a commit that references this issue on Jul 18, 2024
  14. added 2 commits that reference this issue on Jul 18, 2024
  15. added 2 commits that reference this issue on Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    easyinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions