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


Groups > comp.lang.python > #39221

Re: Making unhashable object

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; "'a'": 0.07; 'python': 0.09; 'subclass': 0.09; 'typeerror:': 0.09; 'def': 0.10; 'a(object):': 0.16; 'distinction': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hashable,': 0.16; 'old-style': 0.16; 'subject:object': 0.16; 'type:': 0.16; 'unhashable': 0.16; 'wed,': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'feb': 0.19; 'define': 0.20; 'trying': 0.21; '"",': 0.22; 'exists.': 0.22; 'class.': 0.23; 'header:In-Reply-To:1': 0.25; '(most': 0.27; 'am,': 0.27; 'object,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'received:209.85.212': 0.28; 'skip:_ 10': 0.29; 'class': 0.29; 'url:python': 0.32; 'file': 0.32; 'instances': 0.33; 'traceback': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'received:209.85': 0.35; 'url:org': 0.36; 'should': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; '20,': 0.65; '2013': 0.84; 'subject:Making': 0.84; 'url:__hash__': 0.84; 'url:datamodel': 0.84; 'url:html#object': 0.84; 'url:reference': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=/tpSo50MLE2Q+Aw39vpkNsoLZXCd0uJDQw6wQ4i8RNc=; b=dgRiDqKUEFFFOeciDof7WukokmclQ1lmGcteYTU72VjedDxk/NTo2xDZxd3s3OdydK k22ex1a7Uqt6rFBjvVRy3bkuTGoY9aHkJSi0DfGntN9bB3RiplD918B1MBEv3xO/JrUn 961/7DfhkN7we9dkLkcayglszgIBUIvJ5k41qwirkoXV4g0rFXrqX4/m2lc+34m2kSjg JYzrDULKSUVAPWSSKy5d4WnGbdzl/RBd3ddxqVV/elOYhP4bU3aR4uVRLBiCvMZ+WdV0 wHFS7Og+t5rZINRwwkFpxLMqZGXlvu5LN+bUEii5rAARFmnGAUxqgOwfPASHrPi9d14L gmDQ==
MIME-Version 1.0
X-Received by 10.52.29.209 with SMTP id m17mr12267874vdh.111.1361281581576; Tue, 19 Feb 2013 05:46:21 -0800 (PST)
In-Reply-To <20130219143825.3077c3b8@pcolivier.chezmoi.net>
References <20130219143825.3077c3b8@pcolivier.chezmoi.net>
Date Wed, 20 Feb 2013 00:46:21 +1100
Subject Re: Making unhashable object
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2024.1361281906.2939.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1361281906 news.xs4all.nl 6935 [2001:888:2000:d::a6]:43282
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:39221

Show key headers only | View raw


On Wed, Feb 20, 2013 at 12:38 AM, Olive
<diolu.remove_this_part@bigfoot.com> wrote:
> 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

This is an old-style class. If you subclass object, it works as you expect:

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

>>> a=A(3)
>>> hash(a)

Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    hash(a)
TypeError: unhashable type: 'A'

This is with Python 2.6. With Python 3 and later, that distinction no
longer exists.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next 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