#!/usr/bin/env python2.4 import code class TypedDictionary(dict): def __setitem__(self, key, value): if self.has_key(key): t = type(self[key]) if t != type(value): try: value = t(value) except Exception: raise TypeError, \ "illegal assignment to '%s':" \ " %s cannot be coerced to %s" \ % (key, type(value), t) dict.__setitem__(self, key, value) code.interact(local=TypedDictionary())