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 > or > 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 mind). -- Giovanni Bajo _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com