[Python-ideas] fixing mutable default argument values

George Sakkis gsakkis at rutgers.edu
Thu Jan 18 21:39:01 CET 2007

On 1/18/07, Jim Jewett <jimjjewett at gmail.com> wrote:

> On 1/18/07, Josiah Carlson <jcarlson at uci.edu> wrote:
> > 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])
> But he actually ones a variable that *does* keep state between calls
> (like a mutable default arg), but can't be overridden.
> > With your proposal, you are seeking to attempt to fix a "problem" that
> > no one has complained about.  -1 .
> Sure they have, and they've solved it (under different names) in
> plenty of other languages.  In python, the only current solution seems
> to be turning the function into a class (with self) or at least a
> closure.  People have griped about this.

User-defined function attributes is another handy solution.

> For What Its Worth, my personal opinion is that having to create an
> object instead of a function is annoying, but not so bad (or so
> frequent) that it is worth special syntax.

Function attributes fit the bill really good if writing a class is too
much overhead.


More information about the Python-ideas mailing list