<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">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><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_-7985351514527956135gmail-"><div class="gmail_quote">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><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></div><div class="gmail_extra"><br></div></span>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.</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><div><br></div>-- <br><div class="m_-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>
</div></div>