Re: confusing doc: mutable and hashable

2012-04-29 Thread Terry Reedy
On 4/29/2012 3:57 AM, John O'Hagan wrote: How do function objects fit into this scheme? They have __hash__, __eq__, seem to work as dict keys and are mutable. Is it because their hash value doesn't change? I suspect functions use the default equality and hash based on id, which does not chang

Re: confusing doc: mutable and hashable

2012-04-29 Thread John O'Hagan
On Sat, 28 Apr 2012 11:35:12 -0700 Chris Rebert wrote: [...] > Correct. Pedantically, you can define __hash__() on mutable objects; > it's just not very useful or sensible, so people generally don't. As > http://docs.python.org/reference/datamodel.html#object.__hash__ states > [emphasis added]: >

Re: confusing doc: mutable and hashable

2012-04-28 Thread Arnaud Delobelle
(sent from my phone) On Apr 28, 2012 7:36 PM, "Chris Rebert" wrote: > Correct. Pedantically, you can define __hash__() on mutable objects; > it's just not very useful or sensible, so people generally don't. I find it's fine to define __hash__ on mutable objects as long as __eq__ only relies on im

Re: confusing doc: mutable and hashable

2012-04-28 Thread Terry Reedy
On 4/28/2012 2:09 PM, laymanzh...@gmail.com wrote: In my understanding, there is no directly relation between mutable and hashable in Python. Any class with __hash__ function is "hashable". According the wiki: http://en.wikipedia.org/wiki/Immutable_object In object-oriented and functional prog

Re: confusing doc: mutable and hashable

2012-04-28 Thread MRAB
On 28/04/2012 23:30, Temia Eszteri wrote: Yes, you're right. Being mutable and hashable are orthogonal properties. The implication mutable => non hashable is just a design choice. The reason for such a choice is the following. If a key-element pair K:X is added to a container C and then K

Re: confusing doc: mutable and hashable

2012-04-28 Thread Temia Eszteri
>Yes, you're right. Being mutable and hashable are orthogonal properties. >The implication > mutable => non hashable >is just a design choice. > >The reason for such a choice is the following. If a key-element pair K:X >is added to a container C and then K is changed by some external Python >

Re: confusing doc: mutable and hashable

2012-04-28 Thread Kiuhnm
On 4/28/2012 20:09, laymanzh...@gmail.com wrote: I'm just learning Python. The python doc about mutable and hashable is confusing to me. In my understanding, there is no directly relation between mutable and hashable in Python. Any class with __hash__ function is "hashable". According the wik

Re: confusing doc: mutable and hashable

2012-04-28 Thread Chris Rebert
On Sat, Apr 28, 2012 at 11:09 AM, wrote: > I'm just learning Python. The python doc about mutable and hashable is > confusing to me. > > In my understanding, there is no directly relation between mutable and > hashable in Python. Any class with __hash__ function is "hashable". > > According the

Re: confusing doc: mutable and hashable

2012-04-28 Thread mwilson
laymanzh...@gmail.com wrote: > I'm just learning Python. The python doc about mutable and hashable is > confusing to me. > > In my understanding, there is no directly relation between mutable and > hashable in Python. Any class with __hash__ function is "hashable". > > According the wiki: http:/

confusing doc: mutable and hashable

2012-04-28 Thread laymanzheng
I'm just learning Python. The python doc about mutable and hashable is confusing to me. In my understanding, there is no directly relation between mutable and hashable in Python. Any class with __hash__ function is "hashable". According the wiki: http://en.wikipedia.org/wiki/Immutable_object