Author emilyemorehouse
Recipients emilyemorehouse, eric.smith, gvanrossum, steven.daprano, tim.peters, vstinner, xtreak
Date 2019-01-25.00:36:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1548376594.27.0.861161799255.issue35224@roundup.psfhosted.org>
In-reply-to
Content
@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)
History
Date User Action Args
2019-01-25 00:36:35emilyemorehousesetrecipients: + emilyemorehouse, gvanrossum, tim.peters, vstinner, eric.smith, steven.daprano, xtreak
2019-01-25 00:36:34emilyemorehousesetmessageid: <1548376594.27.0.861161799255.issue35224@roundup.psfhosted.org>
2019-01-25 00:36:34emilyemorehouselinkissue35224 messages
2019-01-25 00:36:34emilyemorehousecreate