Python 2.2b1 hashable dictionary bug?

Mark J maj64 at hotmail.com
Sun Oct 28 22:02:33 EST 2001


Since I haven't had a good hit rate at detecting bugs vs. features, I
thought I'd post here before filing a bug report at SourceForge.

Python 2.2b1 (#1, Oct 19 2001, 23:11:09) 
[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-81)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class D(dictionary): pass
... 
>>> d = {}
>>> d2 = D()
>>> d[d2] = "dictionary used as key"
>>> d
{{}: 'dictionary used as key'}
>>> d[D()]="now have two keys that look the same"
>>> d
{{}: 'now have two keys that look the same', {}: 'dictionary used as
key'}
>>> d2["key"] = "mutable key in d"
>>> d
{{}: 'now have two keys that look the same', {'key': 'mutable key in
d'}: 'dictionary used as key'}
>>> d[d] = "plain dictionary not allowed as key"
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: unhashable type
>>> d2[d2] = "subclassed dictionary allowed though"
>>> d2
{{...}: 'subclassed dictionary allowed though', 'key': 'mutable keys'}
>>> #whoa: what just happened: {...} ??

Interesting....  So is this a feature or a bug?

Thanks,

Mark



More information about the Python-list mailing list