[Python-ideas] Default arguments in Python - the return - running out of ideas but...
Pascal Chambon
chambon.pascal at wanadoo.fr
Mon May 18 22:53:11 CEST 2009
Terry Reedy a écrit :
>
> Curt Hagenlocher wrote:
>
>
>> 1. Preventing the "noob" mistake of saying "def f(x = {})" and
>> expecting that a new empty dictionary will be produced for each call,
>> and
>
> As a couple of us have suggested, this, like similar jobs, should be
> handled by program checkers. I leave it to someone else to see if
> existing programs already check and warn and, if not, suggest this to
> their authors.
>
Indeed, Pylint does handle this in some way :
"W0102: *Dangerous default value %s as argument*
Used when a mutable value as list or dictionary is detected in a
default value
for an argument."
Some have talked about thunks or other concepts here ; I too feel that
this issue could be the occasion of introducing new features, that
exceed the scope of default arguments.
Could you peopel develop a little what you think about with "thunk" or
"early action" ? Is the former different from an argument-less lambda
function ?
Else, concerning the syntax for "dynamic" default arguments, I guesse
somethng like :
def func(a, b @= []):
pass
would be OK, wouldn't it ?
Regards,
Pascal
More information about the Python-ideas
mailing list