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
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.
Activity
JelleZijlstra commentedon Jul 13, 2024
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:
compile.c, currently at line 6122 (search for "'yield' outside function" if it changes).Lib/test/test_generators.py:SyntaxError: 'yield' outside function. The existing test only testsyield, notyield from; we should add more tests.serhiy-storchaka commentedon Jul 13, 2024
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
yieldis valid here.gege-hoho commentedon Jul 13, 2024
I will give it a try :)
pythongh-121657: Display correct error message for yield from outside…
gh-121657: Display correct error message for yield from outside of a …
encukou commentedon Jul 13, 2024
The existing message was technically correct, but
yield fromis definitely better.pythongh-121657: Added an additional test using lambda
pythongh-121657: merge upstream
pythongh-121657: Added an additional test using lambda
[3.13] pythongh-121657: Display correct error message for yield from …
[3.13] gh-121657: Display correct error message for yield from outsid… (
[3.12] gh-121657: Display correct error message for yield from outsid… (
pythongh-121657: Switch test order for better grouping
pythongh-121657: Display correct error message for yield from outside…
gh-121657: Additional `yield from` error test using lambda (GH-121722)
pythongh-121657: Additional `yield from` error test using lambda (pyt…
pythongh-121657: Additional `yield from` error test using lambda (pyt…
[3.13] gh-121657: Additional `yield from` error test using lambda (GH…
[3.12] gh-121657: Additional `yield from` error test using lambda (GH…