[Bug] bool type cannot be used as dict key
jalfje opened this issue · comments
Jamie St Martin commented
(Seq 0.9.10)
This is not so useful except when the bool
is part of a tuple, e.g. d = dict[tuple[int, bool], int]()
. Minimum working example:
d = dict[tuple[int, bool], int]()
d[(0, True)] = 1
Gives the error:
builtin.seq:116:12: error: cannot find method '__hash__' for type 'bool' with specified argument types ()
Currently a workaround is probably to extend the bool
type, but it would be nice for that to be built-in.
A. R. Shajii commented
Thanks for pointing this out; we'll definitely add it in the next release!
A workaround in the meantime is extend
as you mentioned:
extend bool:
def __hash__(self: bool):
return int(self)
Ibrahim Numanagić commented
Fixed in #132