[Python-ideas] Mutable default arguments - another approach

George Sakkis george.sakkis at gmail.com
Tue Jan 30 18:22:54 CET 2007

On 1/30/07, Piotr Duda <duda.piotr at gmail.com> wrote:

> I think that this problem can be solved by the following change of
> default argument behavior:
> default arguments are evaluated in definition time (like in current
> implementation), but right after being evaluated, result object is
> checked if it's mutable (for example by checking of presence __copy__
> special method or being instance of built in (sub)class
> list/dict/set)
> (snipped)

AFAIK there's no reliable way of deciding whether an arbitrary object
is mutable or not, so the rest of the post is irrelevant. Besides,
mutable default arguments is just a specific use case; the general
problem discussed here is call-time vs definition-time semantics for
arbitrary default argument expressions (function calls, attribute
lookups, etc.).


More information about the Python-ideas mailing list