[Python-ideas] Documenting Python warts
Greg Ewing
greg.ewing at canterbury.ac.nz
Wed Jan 2 05:25:13 CET 2013
alex23 wrote:
> The "internal sense" of mutable defaults is that everything is an
> object, and that functions arguments are declared at definition and
> not run-time. What you call "implementation artifact" I see as
> expected behaviour; any other implementation that didn't provide this
> wouldn't be Python in a number of fundamental ways.
What the people who object to this behaviour are really
complaining about is not that the default value is mutable,
but that the default expression is not re-evaluated on
every call.
To me, the justification for this is clear: most of the
time, evaluation on every call is not necessary, so doing
it would be needlessly inefficient. For those cases where
you need a fresh value each time, there is a straightforward
way to get it.
--
Greg
More information about the Python-ideas
mailing list