On 2014-01-15 01:27, Steven D'Aprano wrote: > class TextOnlyDict(dict): > def __setitem__(self, key, value): > if not isinstance(key, str): > raise TypeError > super().__setitem__(key, value) > # need to override more methods too > > > But reading Guido, I think he's saying that wouldn't be a good > idea. I don't get it -- it's not a violation of the Liskov > Substitution Principle, because it's more restrictive, not less. > What am I missing?
Just as an observation, this seems almost exactly what anydbm does, behaving like a dict (whether it inherits from dict, or just duck-types like a dict), but with the limitation that keys/values need to be strings. -tkc -- https://mail.python.org/mailman/listinfo/python-list