Message354601
PEP 572 says that "an assignment expression occurring in a (...) comprehension (...) binds the target in the containing scope, honoring a nonlocal or global declaration for the target in that scope, if one exists."
In Appendix B, the PEP shows this example :
def f():
global TARGET
a = [TARGET := EXPR for VAR in ITERABLE]
So I don't understand why this fails:
Python 3.8.0rc1 (tags/v3.8.0rc1:34214de, Oct 1 2019, 18:42:37) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> x = 0
>>> def f():
... global x
... [x := i for i in range(5)]
...
File "<stdin>", line 3
SyntaxError: no binding for nonlocal 'x' found
>>>
Is this a bug or am I missing something ? |
|
Date |
User |
Action |
Args |
2019-10-13 20:54:11 | quentel | set | recipients:
+ quentel |
2019-10-13 20:54:11 | quentel | set | messageid: <1571000051.15.0.611092311064.issue38469@roundup.psfhosted.org> |
2019-10-13 20:54:11 | quentel | link | issue38469 messages |
2019-10-13 20:54:10 | quentel | create | |
|