Antoon Pardon wrote: > The question is, should we consider this a problem. Personnaly, I > see this as not very different from functions with a list as a default > argument. In that case we often have a list used as a constant too. > > Yet python doesn't has a problem with mutating this list so that on > the next call a 'different' list is the default. So if mutating > a list used as a constant is not a problem there, why should it > be a problem in your example? > Are you serious about that?
The semantics of default arguments are quite clearly defined (although suprising to some people): the default argument is evaluated once when the function is defined and the same value is then reused on each call. The semantics of list constants are also clearly defined: a new list is created each time the statement is executed. Consider: res = [] for i in range(10): res.append(i*i) If the same list was reused each time this code was executed the list would get very long. Pre-evaluating a constant list and creating a copy each time wouldn't break the semantics, but simply reusing it would be disastrous. -- http://mail.python.org/mailman/listinfo/python-list