<div dir="ltr"><div>I'm really surprised no one seems to get my point here. <br><br></div>TL;DR:<br>My point is that having type annotation syntax required for something in the stdlib is a significant step toward "normalizing" type hinting in Python. Whether that's a good idea or not is a judgement call, but it IS a big step.<br><div><div class="gmail_extra"><br><br><div class="gmail_quote">@Chris<br><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><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div>People are still allowed not to use dataclasses if they really don't like type hints :-)<br></div>Seriously however, annotations are just syntax. In this sense PEP 526 is more like PEP 3107,</div><div>and less like PEP 484. People are still free to write:<br></div><br></div>@dataclass<br></div>class C:<br></div>    x: "first coordinate"<br></div>    y: "second coordinate"<br></div>    plus: "I don't like types"<br></div></div></div></div></div></div></div></div></div></div></div></div></blockquote><div><br></div><div>Well, yes, of course, but this is not like PEP 3107, as it introduces a requirement for annotations (maybe not *type* annotations per se) in the std lib. Again, that may be the best way to go -- but it should be done deliberately.<br></div><div><br>@dataclass<br></div><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><div><div><div><div><div><div><div>class C:<br></div>    x: ...<br></div>    y: ...<br></div></div></div></div></div></div></div></blockquote><div><br></div><div>Ah! I had no idea you could use ellipses to indicate no type. That actually helps a lot. We really should have that prominent in the docs. And in the dataclass docs, not just the type hinting docs -- again, people will want to use these that may not have any interest in nor prior knowledge of type hints.<br></div><div><br> </div><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><div><div><div><div><div></div>I don't see so big difference between hypothesis (testing lib) using annotations for their purposes<br></div>from the situation with dataclasses.</div></div></div></div></div></blockquote><div><br></div><div>The big difference is that hypothesis is not in the standard library. Also, I didn't know about hypothesis until just now, but their very first example in the quick start does not use annotation syntax, so it's not as baked in as it is with dataclasses.<br></div><div> </div><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>If you have ideas about how to improve the dataclass docs, this can be discussed in the issue <a href="https://bugs.python.org/issue32216" target="_blank">https://bugs.python.org/<wbr>issue32216</a></div></div></blockquote><div><br>I'll try to find time to contribute there -- though maybe better to have the doc draft in gitHub?<br></div><div><br></div><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>> ... the type will in fact be completely ignored by the implementation.<span class="gmail-"><div style="font-size:12.8px"></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></span><div style="font-size:12.8px">This is not different from</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">def f(x: int):</div><div style="font-size:12.8px">    pass</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">f("What")  # OK</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">that exists starting from Python 3.0. Although I agree this is confusing, the way forward could be just explaining this better in the docs.</div></div></div></blockquote><div><br></div><div>Again the difference is that EVERY introduction to defining python functions doesn't use the type hint. And even more to the point, you CAN define a function without any annotations.<br><br></div><div>But frankly, I think as type hinting becomes more common, we're going to see a lot of confusion :-(<br></div><br><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><div style="font-size:12.8px">If you want my personal opinion about the current situation about type hints _in general_, then I can say that</div><div style="font-size:12.8px">I have seen many cases where people use type hints where they are not needed</div><div style="font-size:12.8px">(for example in 10 line scripts or in highly polymorphic functions), so I agree that some community</div><div style="font-size:12.8px">style guidance (like PEP 8) may be helpful. </div></div></div></blockquote><div><br></div><div>It's going to get worse before it gets better :-(<br></div><div><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-im">@dataclass</span><br><span class="gmail-im">
class C:</span><br><span class="gmail-im">
     x = field()</span></blockquote><div><br></div><div>that does require that `field` be imported, so not as nice. I kinda like the ellipses better. <br></div><br clear="all"></div></div>but good to have a way.<br><br></div><div class="gmail_extra">-Chris<br></div><div class="gmail_extra"><br><br>-- <br><div class="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></div></div>