Should Python raise a warning for mutable default arguments?

MRAB google at mrabarnett.plus.com
Fri Aug 22 14:18:13 EDT 2008


On Aug 22, 4:09 pm, Christian Heimes <li... at cheimes.de> wrote:
> 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.
>
Could there be a new special method __mutable__?



More information about the Python-list mailing list