Why are types not hashable?

Martin v. Loewis martin at v.loewis.de
Wed May 29 02:47:37 EDT 2002


"Andrew Dalke" <dalke at dalkescientific.com> writes:

> I can't reproduce what you get on my machine.  For example,
> what is
>   typestrings[eval('types.' + t): t]
> ?  It looks like a slice, as in
>   typestrings[types.DictionaryType: "DictionaryType"]
> 
> (Trying this on 1.5.2 yields 'TypeError: slice index must be int'
>  .. a-ha!  Under 2.2 it yields your exception)

Indeed, this is the same as

typestrings.__getitem__(slice(eval('types.' + t), t))

It is the slice objects which are unhashable, hence the error.

Regards,
Martin



More information about the Python-list mailing list