<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Sep 11, 2017 at 6:51 AM, Eric V. Smith <span dir="ltr"><<a href="mailto:eric@trueblade.com" target="_blank">eric@trueblade.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 9/11/17 9:43 AM, <a href="mailto:tds333@mailbox.org" target="_blank">tds333@mailbox.org</a> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Eric,<br>
<br>
I have on question not addressed yet.<br>
The implementation is based on "__annotations__" where the type is specified.<br>
But "__annotations__" is not always filled. An interpreter version with special optimization<br>
could remove all __annotations__ for performance reasons. (Discussed in other threads)<br>
<br>
In this case the dataclass does not work or will there be a fallback?<br>
<br>
I know it is a little bit hypothetical because an interpreter with this optimization is<br>
not there yet. I am looking only in the future a bit.<br>
Asking this because type annotations are stated as completely optional for Python.<br>
And this use case will break this assumption.<br>
</blockquote>
<br></span>
Yes, if there are no __annotations__, then Data Classes would break. typing.NamedTuple has the same issue. We discussed it a little bit last week, but I don't think we came to any conclusions.<br>
<br>
Since @dataclass ignores the value of the annotation (except for typing.ClassVar), it would continue to work if the type was present, buy maybe mapped to None or similar.<span class="HOEnZb"><font color="#888888"></font></span><br></blockquote></div></div><div class="gmail_extra"><br></div><div class="gmail_extra">Let's not worry about a future where there's no __annotations__. Type annotations will gradually become more mainstream. You won't have to use them, but some newer features of the language will be inaccessible if you don't. This has already started with the pattern based on inheriting from typing.NamedTuple and using field annotations. Dataclasses are simply another example.</div><div class="gmail_extra"><br></div><div class="gmail_extra">(That said, I strongly oppose *runtime type checking* based on annotations. It's by and large a mistaken idea. But this has nothing to do with that.)<br clear="all"></div><div class="gmail_extra"><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></div>