[Python-Dev] defaultdict proposal round three
rasky at develer.com
Tue Feb 21 08:51:03 CET 2006
Raymond Hettinger wrote:
>> - It would be unwise to have a default value that would be called if
>> it was callable: what if I wanted the default to be a class instance
>> that happens to have a _call_ method for unrelated reasons?
>> Callability is an elusive propperty; APIs should not attempt to
>> dynamically decide whether an argument is callable or not.
> That makes sense, though it seems over-the-top to need a zero-factory
> for a multiset.
> An alternative is to have two possible attributes:
> d.default_factory = list
> d.default_value = 0
> with an exception being raised when both are defined (the test is
> done when the
> attribute is created, not when the lookup is performed).
What does this buy over just doing:
d.default_factory = lambda: 0
which is also totally unambiguous wrt the semantic of usage of the default
value (copy vs deepcopy vs whatever)? Given that the most of the default values
I have ever wanted to use do not even require a lambda (list, set, int come to
More information about the Python-Dev