[Python-ideas] Documenting Python warts
alex23
wuwei23 at gmail.com
Wed Jan 2 12:05:39 CET 2013
On Jan 2, 2:25 pm, Greg Ewing <greg.ew... at canterbury.ac.nz> wrote:
> 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.
Sorry, I should have said "mutable arguments" over "defaults", because
the problem also bites people passing mutable objects to functions and
expecting them to be copied.
> 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.
Absolutely agreed. I have deliberately used this behaviour on a number
of occasions in ways that I believe makes my code clearer, so it
always frustrates me to hear it described as a "wart".
More information about the Python-ideas
mailing list