Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #39217

Making unhashable object

From Olive <diolu.remove_this_part@bigfoot.com>
Newsgroups comp.lang.python
Subject Making unhashable object
Date 2013-02-19 14:38 +0100
Organization Aioe.org NNTP Server
Message-ID <20130219143825.3077c3b8@pcolivier.chezmoi.net> (permalink)

Show all headers | View raw


I am trying to define a class whose instances should not be hashable, following: http://docs.python.org/2/reference/datamodel.html#object.__hash__

class A:
    def __init__(self,a):
        self.value=a
    __hash__=None
    

Then:

>>> a=A(3)
>>> hash(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable
>>> hash([2])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'

I would expect the same error in both case and the error is confusing in the first case. What's the proper way of making an object non hashable?

Olive

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Making unhashable object Olive <diolu.remove_this_part@bigfoot.com> - 2013-02-19 14:38 +0100
  Re: Making unhashable object Chris Angelico <rosuav@gmail.com> - 2013-02-20 00:46 +1100
  Re: Making unhashable object Peter Otten <__peter__@web.de> - 2013-02-19 14:54 +0100

csiph-web