<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Thu, Dec 21, 2017 at 3:10 PM MRAB <<a href="mailto:python@mrabarnett.plus.com">python@mrabarnett.plus.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 2017-12-21 22:45, Chris Barker wrote:<br>
> On Thu, Dec 21, 2017 at 11:55 AM, Terry Reedy <<a href="mailto:tjreedy@udel.edu" target="_blank">tjreedy@udel.edu</a><br>
> <mailto:<a href="mailto:tjreedy@udel.edu" target="_blank">tjreedy@udel.edu</a>>> wrote:<br>
><br>
>     I think the understanding problem with this feature arises from two<br>
>     factors: using annotations to define possibly un-initialized slots<br>
>     is non-obvious; a new use of annotations for something other than<br>
>     static typing is a bit of a reversal of the recent pronouncement<br>
>     'annotations should only be used for static typing'.<br>
><br>
><br>
> you know, that may be where part of my confusion came from -- all the<br>
> talk lately has been about "type hints" and "type annotations" -- the<br>
> idea of "arbitrary annotations" has been lost.<br>
><br>
>     Therefore, getting the permanent doc 'right' is important.<br>
><br>
><br>
> yup.<br>
><br>
>     @dataclass<br>
>     class C:<br>
>          x<br>
>          y = 0<br>
><br>
>     I think the doc should explicitly say that uninitialized fields<br>
>     require annotation with something (anything, not necessarily a type)<br>
>     simply to avoid NameError during class creation.<br>
><br>
><br>
> would this be possible?<br>
><br>
> @dataclass<br>
> class C:<br>
>      x:<br>
>      y: = 0<br>
><br>
> That is -- the colon indicates an annotation, but in this case, it's a<br>
> "nothing" annotation.<br>
><br>
><br>
"..." or "pass", perhaps?<br>
<br>
@dataclass<br>
class C:<br>
      x: ...<br>
      y: ... = 0<br>
<br>
or:<br>
<br>
@dataclass<br>
class C:<br>
      x: pass<br>
      y: pass = 0<br></blockquote><div><br></div><div>pass does not currently parse in that context.  Otherwise I was thinking the same thing.  But we already have ... which does - so I'd suggest that for people who are averse to importing anything from typing and using the also quite readable Any.  (ie: document this as the expected practice with both having the same meaning)</div><div><br></div><div>While I consider the annotation to be a good feature of data classes, it seems worth documenting that people not running a type analyzer should avoid declaring a type. A worse thing than no-type being specified is a wrong type being specified. That appearing in a library will break people who need their code to pass the analyzer and pytype, mypy, et. al. could be forced to implement a typeshed.pypi of sorts containing blacklists of known bad annotations in public libraries and/or actually correct type specification overrides for them.</div><div><br></div><div>As for problems with order, if we were to accept</div><div><br></div><div>@dataclass</div><div>class Spam:</div><div>    beans = True</div><div>    ham: bool</div><div><br></div><div>style instead, would it be objectionable to require keyword arguments only for dataclass __init__ methods?  That'd get rid of the need to care about order.  (but would annoy people with small 2-3 element data classes... so I'm assuming this idea is already rejected)</div><div><br></div><div>-gps</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
> It's a syntax error now, but would it be possible to change that? Or<br>
> would the parsing be ambiguous? particularly in other contexts.<br>
><br>
> of course, then we'd need something to store in as a "nothing"<br>
> annotation -- empty string? None? (but None might mean something) create<br>
> yet anther type for "nothing_annotation"<br>
><br>
> Hmm, I may have talked myself out of it....<br>
><br>
_______________________________________________<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/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/greg%40krypto.org" rel="noreferrer" target="_blank">https://mail.python.org/mailman/options/python-dev/greg%40krypto.org</a><br>
</blockquote></div></div>