[Python-ideas] fixing mutable default argument values

Josiah Carlson jcarlson at uci.edu
Thu Jan 18 17:42:00 CET 2007


Joel Bender <jjb5 at cornell.edu> wrote:
> 
> Calvin Spealman wrote:
> 
> > I dont understand how that would be different than doing
> > 
> >   c = c if c is not None else Bar([2,3,4])
> > 
> 
> Because that would be calling Bar(), perhaps creating a new Bar object, 
> every time foo() is called with None for c, which is not what a default 
> argument values are about.  I'm proposing a way to create function local 
> singleton objects, removing them from the parameter list.
[snip]
> and then hoping that nobody calls foo() with a history parameter.

With your proposal, you are seeking to attempt to fix a "problem" that
no one has complained about.  -1 .


 - Josiah




More information about the Python-ideas mailing list