Re: "specialdict" module

2005-04-05 Thread Steven Bethard
Georg Brandl wrote: Georg Brandl wrote: Hello, in follow-up to the recent "dictionary accumulator" thread, I wrote a little module with several subclassed dicts. Comments (e.g. makes it sense to use super), corrections, etc.? Is this PEP material? Docstrings, Documentation and test cases are to be

Re: "specialdict" module

2005-04-05 Thread Georg Brandl
Georg Brandl wrote: > Hello, > > in follow-up to the recent "dictionary accumulator" thread, I wrote a > little module with several subclassed dicts. > > Comments (e.g. makes it sense to use super), corrections, etc.? Is this > PEP material? > > Docstrings, Documentation and test cases are to be

Re: "specialdict" module

2005-04-04 Thread Georg Brandl
Georg Brandl wrote: > Michele Simionato wrote: >> About not using super: you might have problems in multiple inheritance. >> Suppose I want to use both your defaultdict and a thirdpartdict. A >> subclass >> >> class mydict(defaultdict, thirdpartdict): >>pass >> >> would not work if thirdpartd

Re: "specialdict" module

2005-04-04 Thread Georg Brandl
Michele Simionato wrote: > About not using super: you might have problems in multiple inheritance. > Suppose I want to use both your defaultdict and a thirdpartdict. A > subclass > > class mydict(defaultdict, thirdpartdict): >pass > > would not work if thirdpartdict requires a non-trivial __i

Re: "specialdict" module

2005-04-04 Thread Michele Simionato
About not using super: you might have problems in multiple inheritance. Suppose I want to use both your defaultdict and a thirdpartdict. A subclass class mydict(defaultdict, thirdpartdict): pass would not work if thirdpartdict requires a non-trivial __init__ , since without super in defaultdic

Re: "specialdict" module

2005-04-04 Thread Michele Simionato
Michael Spencer: > Alternatively, you could provide factory functions to construct the defaultdict. > Someone (Michele?) recently posted an implementation of this Yes, here is the link for the ones who missed that thread: http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/a0b

Re: "specialdict" module

2005-04-04 Thread Georg Brandl
Michael Spencer wrote: > Georg Brandl wrote: > >> >> I think I like Jeff's approach more (defaultvalues are just special >> cases of default factories); there aren't many "hoops" required. >> Apart from that, the names just get longer ;) > > Yes Jeff's approach does simplify the implementation a

Re: "specialdict" module

2005-04-03 Thread Michael Spencer
Georg Brandl wrote: I think I like Jeff's approach more (defaultvalues are just special cases of default factories); there aren't many "hoops" required. Apart from that, the names just get longer ;) Yes Jeff's approach does simplify the implementation and more-or-less eliminates my complexity obje

Re: "specialdict" module

2005-04-03 Thread Georg Brandl
Michael Spencer wrote: > 1. Given that these are specializations, why not have: > > class defaultvaluedict(dict): > ... > > class defaultfactorydict(dict): > ... > > rather than having to jump through hoops to make one implementation satisfy > both > cases I think I like Jeff's app

Re: "specialdict" module

2005-04-03 Thread Michael Spencer
Georg Brandl wrote: Hello, in follow-up to the recent "dictionary accumulator" thread, I wrote a little module with several subclassed dicts. Comments (e.g. makes it sense to use super), corrections, etc.? Is this PEP material? Docstrings, Documentation and test cases are to be provided later. mfg

Re: "specialdict" module

2005-04-03 Thread Georg Brandl
Jeff Epler wrote: > 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)) Somehow I feared that this would happen. > In defaultdict, I w

Re: "specialdict" module

2005-04-03 Thread Jeff Epler
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 setde

"specialdict" module

2005-04-03 Thread Georg Brandl
Hello, in follow-up to the recent "dictionary accumulator" thread, I wrote a little module with several subclassed dicts. Comments (e.g. makes it sense to use super), corrections, etc.? Is this PEP material? Docstrings, Documentation and test cases are to be provided later. mfg Georg -