[IronPython] Tuple Hashing and Dictionaries
Dino Viehland
dinov at exchange.microsoft.com
Thu Jun 15 02:22:32 CEST 2006
I've also opened an issue to track this on CodePlex (#469)
-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord
Sent: Wednesday, June 14, 2006 7:03 AM
To: Discussion of IronPython
Subject: [IronPython] Tuple Hashing and Dictionaries
Hello all,
We have created a custom object which we wanted to use as a dictionary key as part of a tuple.
To make sure that equivalent instances of our class can be used as keys we overloaded the __hash__ method.
This works in CPython, but not in IronPython. The following test sessions both use the following class :
class Test(object):
def __hash__(self):
return hash("fish")
def __eq__(self, other):
return type(other) == type(self)
CPython :
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> a = Test()
>>> b = Test()
>>> a == b
True
>>> c = {}
>>> c[(a, 1, 2)] = 3
>>> c[(b, 1, 2)]
3
IronPython :
IronPython 1.0.60420 (Beta) on .NET 2.0.50727.42 Copyright (c) Microsoft Corporation. All rights reserved.
>>> a = Test()
>>> b = Test()
>>> a == b
True
>>> c = {}
>>> c[(a, 1, 2)] = 3
>>> c[(b, 1, 2)]
Traceback (most recent call last):
File , line 0, in input##22
KeyError: '(<Test object at 0x000000000000002B>, 1, 2)'
All the best,
Michael Foord
http://www.resolversystems.com
http://www.voidspace.org.uk/python/index.shtml
_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
More information about the Ironpython-users
mailing list