<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Aug 1, 2016 at 10:31 PM, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>
Second, when these occur in a class body, they can define either class<br>
variables or instance variables. Do we need to be able to specify<br>
which?<br></blockquote><div><br></div><div>I'd say that if I have a class C with a class variable cv, instance variable iv, a good type checking system should detect:</div><div><br></div><div><font face="monospace, monospace">C.cv # ok</font></div><div><font face="monospace, monospace">C.iv # error!</font></div><div><font face="monospace, monospace">C().iv # ok</font></div><div> </div><div>which is something that PEP484 doesn't clarify much (and mypy flags all 3 as valid)</div><div><br></div><div>So in short, I think it is relevant to specify differently class vs instance vars.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Suppose we wanted to add types to the latter. Would we write this as<br>
<br>
a, b: int, str = 0, ''<br>
<br>
or as<br>
<br>
a: int, b: str = 0, ''<br>
<br>
??? Personally I think neither is acceptable, and we should just write it as<br>
<br>
a: int = 0<br>
b: str = ''<br>
<br>
but this is a slight step back from<br>
<br>
a, b = 0, '' # type: (int, str)<br></blockquote><div><br></div><div>I'm not specially fond of the «# type: (int, str)». It works ok for 2 variables, but for more it is hard to mentally "align" the variable names to the type names, for example in:</div><div><br></div><div><font face="monospace, monospace">kind, text, start, end, line = token # type: (int, str, Tuple[int, int], Tuple[int, int], str)</font></div><div><br></div><div>it's not easy to quickly answer "what is the type of 'end' here?". So I wouldn't miss that notation a lot if it went away</div><div><br></div><div>Given that, I'm happier with both the 2-line solution and the second one-liner, which both keep the types closer to the names. But given that as you mentioned:</div><div><br></div><div><font face="monospace, monospace">kind: int, text:str, start: Tuple[int, int], end: Tuple[int, int], line: str = token</font></div><div><br></div><div>looks a bit misleading (looks more like an assignment to token), perhaps it would avoid errors to accpt as valid only:</div><div><br></div><div><div><font face="monospace, monospace">(kind: int, text:str, start: Tuple[int, int], end: Tuple[int, int], line: str) = token</font></div></div><div><br></div><div>other possibility if you really love the current mypy syntax (perhaps both could be valid):</div><div><br></div><div><div><div><font face="monospace, monospace">(kind, text, start, end, line):</font><span style="font-family:monospace,monospace">(int, str, Tuple[int, int], Tuple[int, int], str)</span><span style="font-family:monospace,monospace"> = token</span></div></div><div><font face="monospace, monospace"><br></font></div><div>I don't like that one very much, but perhaps it inspires ideas on someone here.<br></div></div><div><br></div><div>Other places to think about are:</div><div><br></div><div>* Multiple assignment (Chris mentioned these)</div><div>* loop variables (in a for statement, comprehensions, generator expressions)</div><div>* lambda arguments</div><div><br></div><div><br></div></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr">Daniel F. Moisset - <span style="font-size:small">UK Country Manager</span><div><a href="http://www.machinalis.com" target="_blank">www.machinalis.com</a></div><div>Skype: @dmoisset</div></div></div></div></div>
</div></div>