[Python-ideas] fixing mutable default argument values

Jim Jewett jimjjewett at gmail.com
Thu Jan 18 20:00:12 CET 2007


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.

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.

-jJ



More information about the Python-ideas mailing list