Should Python raise a warning for mutable default arguments?

Christian Heimes lists at cheimes.de
Fri Aug 22 11:09:34 EDT 2008


Steven D'Aprano wrote:
> I suggest that Python should raise warnings.RuntimeWarning (or similar?) 
> when a function is defined with a default argument consisting of a list, 
> dict or set. (This is not meant as an exhaustive list of all possible 
> mutable types, but as the most common ones that I expect will trip up 
> newbies.) The warning should refer to the relevant FAQ or section in the 
> docs.
> 
> What do people think?

I don't see a chance for your proposal. How are you going to detect 
mutable objects? Custom types can be mutable as well as immutable.

Christian




More information about the Python-list mailing list