The software you used to post this message wrapped some of the lines of
code.  For example:
>     def __delitem__(self, key):
>         super(keytransformdict, self).__delitem__(self,
> self._transformer(key))

In defaultdict, I wonder whether everything should be viewed as a
factory:
    def setdefaultvalue(self, value):
        def factory(): return value
        self.setdefaultfactory(factory)

and the "no-default" mode would either cease to exist, or 
    def cleardefault(self):
        def factory(): 
            raise KeyError, "key does not exist and no default defined"
        self.setdefaultfactory(factory)
(too bad that the key isn't available in the factory, this degrades the
quality of the error messge)

if so, __getitem__ becomes simpler:
    __slots__ = ['_default']
    def __getitem__(self, key):
      try:
          return super(defaultdict, self).__getitem__(key)
      except KeyError:
          return self.setdefault(key, apply(*self._default))

I don't ever have an itch for sorted dictionaries, as far as I can
remember, and I don't immediately understand the use of
keytransformdict.  Can you give an example of it?

Jeff

Attachment: pgpTcdOKCij9W.pgp
Description: PGP signature

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to