<div dir="auto"><div dir="auto"><span style="font-family:sans-serif">Hi Sven,</span></div><div dir="auto"><span style="font-family:sans-serif"><br></span></div><div><span style="font-family:sans-serif">"I hope the second ': int' can be omitted because 0 already is an int."</span></div><div dir="auto"><br></div><div dir="auto">0 is also an Any, an object, a SupportAbs, and a Union[int, str].</div><div dir="auto">And infinitely more, of course.</div><div dir="auto"><br></div><div dir="auto">A typechecker needs to be explicitly told which was intended.</div><div dir="auto"><br></div><div dir="auto">Stephan</div><div dir="auto"><div class="gmail_extra" dir="auto"><br><div class="gmail_quote">Op 17 mei 2017 19:52 schreef "Sven R. Kunze" <<a href="mailto:srkunze@mail.de">srkunze@mail.de</a>>:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
Hi Stephan,<br>
hi Ivan,<div class="quoted-text"><br>
<br>
On 17.05.2017 18:48, Ivan Levkivskyi wrote:<br>
<blockquote type="cite">
<div dir="ltr">from typing import NamedTuple<br>
<div class="gmail_extra">
<div class="gmail_quote">
<div><br>
</div>
<div>class Foo(NamedTuple):<br>
</div>
<div> """Foo is a very important class and<br>
you should totally use it.<br>
"""<br>
</div>
<div> bar: int<br>
</div>
<div> baz: int = 0<br>
<br>
</div>
<div> def grand_total(self):<br>
return self.bar + self.baz<br>
<br>
</div>
<div>typing.NamedTuple supports docstrings, user-defined
methods, and default values.<br>
</div>
</div>
</div>
</div>
</blockquote>
<br></div>
I hope the second ': int' can be omitted because 0 already is an
int.<br>
<br>
<br>
This makes me wonder three things:<br>
1) Michel, can newcomers differentiate between when to use ' : ' and
when to use ' = ' and a combination thereof?<br>
2) There must be a lot of cornercases where people rewrite Foo to be
a normal class in the end, right?<br>
3) If one doesn't need tuple-__dunder__ methods, a "normal" class
would even need 1 line less. (+ Stephan's second point)<br>
<br>
<br>
So, this still leaves those missing __dunder__ magic methods doing
the right thing at the right time.<font color="#888888"><br>
<br>
<br>
Sven<br>
</font></div>
</blockquote></div><br></div></div></div>