[Python-ideas] Mutable default arguments - another approach

Roman Susi rnd at onego.ru
Tue Jan 30 21:33:31 CET 2007

George Sakkis wrote:
> 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
> 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.).
> George

Maybe Python interpreter could be better at deciding if the programmer
which wrote the code is novice or experienced.

For example,

from __present__ import _I_AM_PYTHON_EXPERT

at the beginning of each module will do ;-)

Or, alternatively, Python interpreter will read user's directory for
some obscure configuration file where programmer will put True's into


(And of course, there will be secret


which will override all the previous settings.)

AFAIK, no language has this feature yet (not sure about Perl).


More information about the Python-ideas mailing list