<div dir="ltr">Sounds good to me.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Nov 12, 2017 at 7:17 AM, Serhiy Storchaka <span dir="ltr"><<a href="mailto:storchaka@gmail.com" target="_blank">storchaka@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Initially generator expressions always had to be written inside parentheses, as documented in PEP 289 [1]. The additional parenthesis could be omitted on calls with only one argument, because in this case the generator expression already is written inside parentheses. You could write just `list(x for x in [1])` instead of `list((x for x in [1]))`. The following code was an error:<br>
<br>
>>> list(x for x in [1], *[])<br>
File "<stdin>", line 1<br>
SyntaxError: invalid syntax<br>
>>> list(x for x in [1],)<br>
File "<stdin>", line 1<br>
SyntaxError: invalid syntax<br>
<br>
You needed to add explicit parenthesis in these cases:<br>
<br>
>>> list((x for x in [1]), *[])<br>
[1]<br>
>>> list((x for x in [1]),)<br>
[1]<br>
<br>
But in Python 2.5 the following examples were accepted:<br>
<br>
>>> list(x for x in [1], *[])<br>
[1]<br>
>>> list(x for x in [1], *{})<br>
[1]<br>
>>> list(x for x in [1],)<br>
[1]<br>
<br>
However I haven't found anything about this change in the "What's New In Python 2.5" document [2].<br>
<br>
The former two cases were found to be a mistake and it was fixed in Python 3.5.<br>
<br>
>>> list(x for x in [1], *[])<br>
File "<stdin>", line 1<br>
SyntaxError: Generator expression must be parenthesized if not sole argument<br>
>>> list(x for x in [1], *{})<br>
File "<stdin>", line 1<br>
SyntaxError: Generator expression must be parenthesized if not sole argument<br>
<br>
But `list(x for x in [1],)` still is accepted. I think it would be better it this raises a SyntaxError.<br>
<br>
1. This syntax is ambiguous, because at first look it is not clear whether it is equivalent to `list((x for x in [1]),)` or to `list(x for x in ([1],))`.<br>
<br>
2. It is bad from the aesthetic point of view, because this is the only case when the generator expression has not written inside parentheses. I believe that allowing to omit parenthesis in a call with a single generator expression argument was caused by aesthetic reasons.<br>
<br>
3. I believe the trailing comma in function call was allowed because this simplified adding, removing and commenting out arguments.<br>
<br>
func(first_argument,<br>
second_argument,<br>
#third_argument,<br>
)<br>
<br>
You shouldn't touch other lines by adding or removing a comma when add or remove arguments. But this reason is not applicable to the case of `list((x for x in [1]),)`, because the generator expression without parenthesis should be the only argument. Therefore there is no reasons to allow this syntax.<br>
<br>
4. 2to3 didn't supported this syntax for recent times [4]. Finally it was changed, but I think that it would be better to disallow this syntax for reasons mentioned above.<br>
<br>
[1] <a href="https://www.python.org/dev/peps/pep-0289/" rel="noreferrer" target="_blank">https://www.python.org/dev/pep<wbr>s/pep-0289/</a><br>
[2] <a href="https://docs.python.org/2.5/whatsnew/whatsnew25.html" rel="noreferrer" target="_blank">https://docs.python.org/2.5/wh<wbr>atsnew/whatsnew25.html</a><br>
[3] <a href="https://docs.python.org/3.5/whatsnew/3.5.html#changes-in-python-behavior" rel="noreferrer" target="_blank">https://docs.python.org/3.5/wh<wbr>atsnew/3.5.html#changes-in-pyt<wbr>hon-behavior</a><br>
[4] <a href="https://bugs.python.org/issue27494" rel="noreferrer" target="_blank">https://bugs.python.org/issue2<wbr>7494</a><br>
<br>
______________________________<wbr>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/guido%40python.org" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/options/python-dev/guido%<wbr>40python.org</a><br>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div>