Emily Morehouse <emilyemoreho...@gmail.com> added the comment:
@vstinner Is there something I could/should have checked other than the CI displayed in GitHub before merging? Let me know if I can help. Here's a brief summary of the differences between the PEP spec and implementation: >From the "Scope of the target" section of the PEP, there are two cases that >should raise a TargetScopeError: when an assignment expression is used in a >comprehension inside a class body or for special cases in comprehensions. Invalid examples for the latter include: [i := i+1 for i in range(5)] [[(j := j) for i in range(5)] for j in range(5)] [i := 0 for i, j in stuff] [i+1 for i in i := stuff] However, the following work in the implementation,though the PEP states they should be invalid: >>> [i := i+1 for i in range(5)] [1, 2, 3, 4, 5] >>> i 5 >>> [i := 0 for i, j in [(1, 2)]] [0] The following does not work in the implementation (as desired), but does not throw a TargetScopeError as defined in the PEP: >>> [i+1 for i in i := range(5)] File "<stdin>", line 1 [i+1 for i in i := range(5)] ^ SyntaxError: invalid syntax IMO, I was leaning towards advocating for changing the PEP to match the implementation. I think the error messages are clear and expected, and restricting what already works would require significant special cases. I'm open to discussion though. There's also documentation that should certainly be added (and I believe a spot where assignment expressions are explicitly mentioned as not being included in the language, which is no longer the case) ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue35224> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com