<div dir="ltr">Good Bad or Neutral, this discussion makes my point:<div><br></div><div>Using typing annotation as a necessary part of a standard library module is injecting typing into "ordinary" python in a new way.</div><div><br></div><div>It is no longer going to appear to be completely optional, and only of concern to those that choose to use it (and mypy or similar).</div><div><br></div><div>And I do think it is really bad UI to have something like:</div><div><br></div><div><div style="font-size:12.8px">@dataclass</div><div style="font-size:12.8px">class C:</div><div style="font-size:12.8px">    a: Int = 1</div><div style="font-size:12.8px">    b: float = 1.0 </div></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">be the recommended (and shown in all the examples, and really be almost the only way) to define a dataclass, when the type will in fact be completely ignored by the implementation.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Newbies are going to be confused by this -- they really are.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Anyway, clearly I personally don't think this is a very good idea, but I see that annotations are a natural and easy way to express the fields without adding any new syntax.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">But most importantly I don't think this should become standard without consideration of the impact and a deliberate decision to do so.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">A note: I don't know who everyone is that was engaged in the gitHub discussion working out the details, but at least a few core folks are very engaged in the introduction of type hinting to Python in general -- so I think a certain perspective may have been over-represented. </div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Are there other options??</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">plain old:</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><font face="monospace, monospace">@dataclass</font></div><div style="font-size:12.8px"><font face="monospace, monospace">class C:</font></div><div style="font-size:12.8px"><font face="monospace, monospace">    a = 1</font></div><div style="font-size:12.8px"><font face="monospace, monospace">    b = 1.0</font></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">would work, though then there would be no way to express fields without defaults:</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><div><font face="monospace, monospace">@dataclass</font></div><div><font face="monospace, monospace">class C:</font></div><div><font face="monospace, monospace">    a = 1</font></div><div><font face="monospace, monospace">    b = None</font></div></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">almost -- but they is there "no default" or is the default None</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Would it be impossible to use the annotation syntax, but with the type optional:</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><font face="monospace, monospace">@dataclass</font></div><div style="font-size:12.8px"><font face="monospace, monospace">class C:</font></div><div style="font-size:12.8px"><font face="monospace, monospace">    a : = 1 # filed with default value</font></div><div style="font-size:12.8px"><font face="monospace, monospace">    b :     # field with no default</font></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">This is not legal python now, but are there barriers other than not wanting to make yet more changes to it being legal (i.e. hard/impossible to unambiguously parse, etc.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Maybe this can all be addresses by more "Untyped" examples  the docs.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">-CHB</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><br></div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Dec 17, 2017 at 8:54 AM, David Mertz <span dir="ltr"><<a href="mailto:mertz@gnosis.cx" target="_blank">mertz@gnosis.cx</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="">On Sun, Dec 17, 2017 at 8:22 AM, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br></span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><span class="m_6618715753658247694m_-7985351514527956135gmail-"><div class="gmail_quote"><span class="">On Sun, Dec 17, 2017 at 2:11 AM, Julien Salort <span dir="ltr"><<a href="mailto:listes@salort.eu" target="_blank">listes@salort.eu</a>></span> wrote:<br></span><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Naive question from a lurker: does it mean that it works also if one<br>
annotates with something that is not a type, e.g. a comment,<br>
<br>
@dataclass<br>
class C:<br>
    a: "This represents the amplitude" = 0.0<br>
    b: "This is an offset" = 0.0</blockquote></span></div><div class="gmail_extra"><br></div></span><span class="">I would personally not use the notation for this, but it is legal code. However static type checkers like mypy won't be happy with this.</span></div></div></blockquote><div><br></div><div>Mypy definitely won't like that use of annotation, but documentation systems might.  For example, in a hover tooltip in an IDE/editor, it's probably more helpful to see the descriptive message than "int" or "float" for the attribute.</div><div><br></div><div>What about data that isn't built-in scalars? Does this look right to people (and will mypy be happy with it)?</div><div><br></div><div>@dataclass</div><div>class C:</div><div>    a:numpy.ndarray = numpy.random.random((3,3))</div><div>    b:MyCustomClass = MyCustomClass("foo", 37.2, 1+2j)</div><div><br></div><div>I don't think those look terrible, but I think this looks better:</div><div><br></div><div>@dataclass</div><div>class C:</div><div>    a:Infer = np.random.random((3,3))</div><div>    b:Infer = MyCustomClass("foo", 37.2, 1+2j) </div></div><div><br></div><div>Where the name 'Infer' (or some other spelling) was a name defined in the `dataclasses` module.  In this case, I don't want to use `typing.Any` since I really do want "the type of thing the default value has."</div><span class="HOEnZb"><font color="#888888"><div><br></div>-- <br><div class="m_6618715753658247694m_-7985351514527956135gmail_signature">Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>advocates of freedom in prisons.  Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br></div>
</font></span></div></div>
<br>______________________________<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/chris.barker%40noaa.gov" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/options/python-dev/<wbr>chris.barker%40noaa.gov</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R            (206) 526-6959   voice<br>7600 Sand Point Way NE   (206) 526-6329   fax<br>Seattle, WA  98115       (206) 526-6317   main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a></div>
</div>