[Python-ideas] Mutable default function parameter warning

Terry Reedy tjreedy at udel.edu
Mon Aug 23 20:06:13 CEST 2010

On 8/23/2010 10:55 AM, Sérgio Surkamp wrote:
> Hello list,
> The documentation states that the default value of function parameter,
> if mutable, can change it's default value at runtime due to be
> evaluated only once on function object creation.
> I would like to suggest the inclusion of an default language warning
> when this kind of construction is used, as it's Python specific
> behavior and can lead to "strange behavior" or misuse by programmers
> that are migrating from other languages to Python.

I am opposed to this for multiple reasons.

1. Static checking is for checking programs, not the compiler. IDLE 
currently has a Run syntax check option. I believe there have be 
proposals to extend that to running external checking programs. I would 
be in favor of that.
2. Dynamic warning are already done -- by eventually raising an 
exception. If no exception is raised, then code is legal and the result 
*might* be correct.
3. There are numerous Python features that *might* be incorrect. For 
instance, reuse of builtin names. This is a long, slippery, slope.
4. Defining 'ismutable' is even harder than defining 'iscallable'.

> This proposal was first open as a suggestion issue in bug track, but,
> as a request from Mr. Peterson, I'm rewriting it to this list.
> http://bugs.python.org/issue9646

Please close the issue when the tracker is working again.

Terry Jan Reedy

More information about the Python-ideas mailing list