Surely what you're looking for is some kind of typed hash table?
Maybe, maybe not. My impression is that the Typed hash table is a kluge to get around this one issue. As others have pointed out, 1 and 1.0 are considered equal, and thus hash the same — a typed hash table would not consider them the same. And while maybe useful, it would violate the spirit of duck typing. If you really want that kind of static typing, maybe Python is not the language for the job. (And since booleans are subclasses of Ints, they might still class in a typed has table, depending on the implementation) What I think the OP wants, and I happen to agree, is for Booleans to not only not BE integers in the subclassing sense, but also to not behave as numbers in the. Duck Typing sense. That is: True == 1 # false True * 4. # Exception Etc. However, that ship has sailed. I think it would have been minimally disruptive when True and False were first introduced, but it’s way too late now. There is far too much code out there that expects the bools to behave like integers. To the OP: perhaps you could create your own non-integer Bool type, and then put a wrapper around set and/or dict, that substitutes it on insertion. Whether that is more or less kludgy than your solution depends on your use case. -CHB Maybe you should be suggesting adding a TypedMapping to collections or
something like that? But it seems to be your solution is fine, but maybe could abstract away the types in the keys in the class dunders?
``` class TypedMapping(dict): def __getitem__(self, item): return super().__getitem__((item, type(item))) ... ``` And so on _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/VAPFAR... Code of Conduct: http://python.org/psf/codeofconduct/
-- Christopher Barker, PhD Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython