<div dir="ltr">I don't seem to be getting my own messages back to reply to, but:<div><br></div><div>yes, of course, dataclasses won't hash if a field is mutable:</div><div>







<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><br></span></p><p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>58</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">]: </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)">@dataclasses</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures">.dataclass(</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">hash</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures">=</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>True</b></span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures">, frozen=</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>True</b></span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures">)</span></p>
<p class="gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">    </span>...: <b>class</b></span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(60,159,242)"><b>Hash</b></span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">:</span></p>
<p class="gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">    </span>...: </span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span class="gmail-Apple-converted-space">    </span>x: </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures">int</span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span class="gmail-Apple-converted-space">  </span>= </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures">5</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><span class="gmail-Apple-converted-space">    </span>...: </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">    </span>l: </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">list</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"> = dataclasses.field(default_factory=</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">list</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures">)</span></p>
<p class="gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">    </span>...:<span class="gmail-Apple-converted-space"> </span></span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> <span class="gmail-Apple-converted-space">   </span></span></p>
<p class="gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">    </span>...:<span class="gmail-Apple-converted-space"> </span></span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> <span class="gmail-Apple-converted-space">   </span></span></p>
<p class="gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">    </span>...:<span class="gmail-Apple-converted-space"> </span></span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> <span class="gmail-Apple-converted-space">   </span></span></p>
<p class="gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">    </span>...:<span class="gmail-Apple-converted-space"> </span></span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> <span class="gmail-Apple-converted-space">   </span></span></p>
<p class="gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>59</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">]: </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures">h = Hash()</span></p>
<p class="gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>60</b></span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures">]: hash</span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">(h)</span></p>
<p class="gmail-p4" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(195,55,32);background-color:rgb(255,255,255)"><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures">---------------------------------------------------------------------------</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)">TypeError</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"> <span class="gmail-Apple-converted-space">                                </span>Traceback (most recent call last)</span></p>
<p class="gmail-p5" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,188,38);background-color:rgb(255,255,255)"><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><ipython-input-60-ad376ae4487e></span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> in </span><span class="gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(51,187,200)"><module></span><span class="gmail-s9" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">()</span></p>
<p class="gmail-p5" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,188,38);background-color:rgb(255,255,255)"><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures">----> 1</span><span class="gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)"> </span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">hash</span><span class="gmail-s9" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">(</span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">h</span><span class="gmail-s9" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">)</span></p>
<p class="gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="gmail-p5" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,188,38);background-color:rgb(255,255,255)"><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures">/Users/chris.barker/miniconda2/envs/py3/lib/python3.6/site-packages/dataclasses.py</span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> in </span><span class="gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(51,187,200)">__hash__</span><span class="gmail-s9" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">(self)</span></p>
<p class="gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)">TypeError</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures">: unhashable type: 'list'</span></p><p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><br></span></p>And the hash does depend on the values of the fields.So you can REALLY ignore my previous note.<br><br>Again, sorry for the noise.<br><br>-CHB<br><p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><br></span></p></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 5, 2018 at 3:37 PM, Steven D'Aprano <span dir="ltr"><<a href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</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 Sun, Feb 04, 2018 at 09:18:25PM -0800, Guido van Rossum wrote:<br>
<br>
> The way I think of it generally is that immutability is a property of<br>
> types, while hashability is a property of values.<br>
<br>
</span>That's a great way to look at it, thanks.<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
--<br>
Steve<br>
</font></span><div class="HOEnZb"><div class="h5">______________________________<wbr>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/chris.barker%40noaa.gov" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/options/python-dev/<wbr>chris.barker%40noaa.gov</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="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>