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 thautwarm
Recipients gvanrossum, serhiy.storchaka, thautwarm, yselivanov
Date 2018-09-29.22:05:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1538258723.92.0.545547206417.issue34845@psf.upfronthosting.co.za>
In-reply-to
Content
Currently we can use `exprlist` as the iterator in a `for` 
statement:

  ```
  for i in 1, 2,:
     print(i)

  1
  2
  ```

  However, when it comes to comprehension expressions:

  ```
  [i for i in 1, 2]

  SyntaxError: invalid syntax
  ```

  I know there might be some reason that leads to the absence of the consistency between `for` expression and statement, but IMO until now it could be better to allow `exprlist` to be the iterator of comprehensions. I'm not sure whether our community has noticed this problem so I'm to propose it here.

  A crucial benefit from this change is that we can avoid the ambiguity when a comprehension is accepted as function parameter.

  ```
  f(for i in [1, 2, 3], 1, 2)
  ```
  We now get a SyntaxError when writing such codes, but people who know this syntax might think the parameters can be distinguished from each other, but it's still not allowed. 
  
  Allowing `exprlist` to be the iterator slot of a comprehension would be a rational solution. If `f(for i in [1, 2, 3], 1, 2)` is equivalent to `f(for i ([1, 2, 3], 1, 2))`, it will be natural to restrict the number of parameters to be just 1 when the parameter is a comprehension.

  You can slightly accept this workaround and try following examples:
  ```
  f(for i in 1,)
  f(for i in 1, for j in 2, 3,)
  f(for i in 1, 2 if cond(i) for j in 3, for k in 4,)
  ```
  Obviously, in each of above cases, the number of parameters is 1,
just because a `exprlist` could the iterator of a comprehension.

  The disadvantage of this change is, there is not too many related use cases, for any `[expr for target in iter_elem1, iter_elem2, ...]` could be altered as `[expr for target in (iter_elem1, iter_elem2, ...)]`. Meanwhile, that might not be true when it comes to someone works frequently with interactive python.
 
  
  Finally, I have finished this implementation at https://github.com/thautwarm/cpython/tree/exprlist-in-comprehensions, and I do want to make contributions to cpython projects. If most of you feel comfortable with this change, may I make a PR next?
History
Date User Action Args
2018-09-29 22:05:23thautwarmsetrecipients: + thautwarm, gvanrossum, serhiy.storchaka, yselivanov
2018-09-29 22:05:23thautwarmsetmessageid: <1538258723.92.0.545547206417.issue34845@psf.upfronthosting.co.za>
2018-09-29 22:05:23thautwarmlinkissue34845 messages
2018-09-29 22:05:23thautwarmcreate