This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author quentel
Recipients quentel
Date 2019-10-13.20:54:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1571000051.15.0.611092311064.issue38469@roundup.psfhosted.org>
In-reply-to
Content
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 ?
History
Date User Action Args
2019-10-13 20:54:11quentelsetrecipients: + quentel
2019-10-13 20:54:11quentelsetmessageid: <1571000051.15.0.611092311064.issue38469@roundup.psfhosted.org>
2019-10-13 20:54:11quentellinkissue38469 messages
2019-10-13 20:54:10quentelcreate