<div dir="ltr">Maybe annotations should get a brief mention in the Rejected Ideas section, with your explanation here added. (And maybe my response.)<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 19, 2018 at 11:31 PM, Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Fri, Apr 20, 2018 at 2:45 PM, Dmitry Malinovsky <<a href="mailto:damalinov@gmail.com">damalinov@gmail.com</a>> wrote:<br>
> Hello Chris, and thank you for working on this PEP!<br>
><br>
> What do you think about using variable type hints with this syntax?<br>
> I tried to search through python-dev and couldn't find a single post<br>
> discussing that question.<br>
> If I missed it somehow, could you please include its conclusions into the PEP?<br>
<br>
</span>I'm ignoring them for the sake of the PEP, because it'd complicate the<br>
grammar for little benefit. If someone wants to add an enhancement<br>
later, that's fine; but the proposal can stand without it, and with<br>
it, it'll make for even more noise in a line full of colons.<br>
<span class=""><br>
> For instance, as I understand now the parser will fail on this snippet:<br>
><br>
> while data: bytes := stream.read():<br>
> print("Received data:", data)<br>
><br>
> Do brackets help?<br>
><br>
> while (data: bytes := stream.read()):<br>
> print("Received data:", data)<br>
><br>
> IIUC, in 3.7 It is invalid syntax to specify a type hint for a for loop item;<br>
> should brackets help? Currently they don't:<br>
><br>
> Python 3.7.0b3+ (heads/3.7:7dcfd6c, Mar 30 2018, 21:30:34)<br>
> [Clang 9.0.0 (clang-900.0.39.2)] on darwin<br>
> Type "help", "copyright", "credits" or "license" for more information.<br>
> >>> for (x: int) in [1,2,3]:<br>
> File "<stdin>", line 1<br>
> for (x: int) in [1,2,3]:<br>
> ^<br>
> SyntaxError: invalid syntax<br>
<br>
</span>And that's another good reason not to bother, at least for now. I'm<br>
not sure whether you can use a Py2-style type hint comment on a for<br>
loop, but if so, you should also be able to do it on a while loop or<br>
anything. Or, of course, you can just annotate the variable before the<br>
loop, if you want to.<br>
<br>
ChrisA<br>
<div class="HOEnZb"><div class="h5">______________________________<wbr>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/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/<wbr>mailman/options/python-dev/<wbr>guido%40python.org</a><br>
</div></div></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>