Bizarre method keyword-arg bug.

Paul Boddie paul at boddie.org.uk
Mon Aug 18 06:04:41 EDT 2008


On 18 Aug, 11:40, Fredrik Lundh <fred... at pythonware.com> wrote:
> Jasper wrote:
> > Uggg!  /That's/ an intuitive side-effect/wart.  :-/
>
> it's done that way on purpose, of course, because evaluating a full
> closure for each default argument at every call would greatly hurt
> performance (and lead to another set of surprises, of course).

Having had the opportunity to reflect on this recently, I'd agree that
the current behaviour is probably the better outcome in many cases,
although one usually only sees people having problems with this when
using literals (lists mostly, and often empty lists), so there's
always the question of how people perceive those literals, whether
they consider them sufficiently "low cost" to be evaluated for each
call, and so on. Indeed, issues of binding don't apply to such
literals, and I imagine that this conceals the possibility of
surprising behaviour (in the general case with names which could refer
to different things at different times) and the rationale for
implementing a mechanism which is consequently less complicated (both
for the developers and in terms of predicting program behaviour).

> please don't label things that you don't understand and haven't spent
> any time reflecting over as bugs or warts; that's disrespectful to the
> designers and probably not good for your blood pressure.

Well, in the page of "Python warts" that I compiled when it was
claimed that Python 3000 addresses such issues in Python 2.x, the
"Mutable default arguments" entry lists at least one experienced
Python author who agrees with the inquirer's assertion:

http://wiki.python.org/moin/PythonWarts

Paul



More information about the Python-list mailing list