[Python-ideas] proto-PEP: Fixing Non-constant Default Arguments

Adam Olsen rhamph at gmail.com
Tue Jan 30 01:07:00 CET 2007


On 1/29/07, Jim Jewett <jimjjewett at gmail.com> wrote:
> On 1/29/07, Roman Susi <rnd at onego.ru> wrote:
>
> > P.S. However, I may be wrong. In that case my syntax suggestion would be
> > this:
>
> > def foo(non_const or []):
> >     ...
> >
> > where [] is executed at runtime BECAUSE at def time non_const is somehow
> > True and that is enough to leave [] alone.
>
> It would also be possible to treat literals (like "[]") as "do it over
> each time", and more general expressions (like "list()") as they are
> treated today.
>
> Though like Roman, I think this would still be worse than the status quo.

Another, more bizarre approach would be to require default arguments
be hashable.  This would prevent lists from being used, protecting
people from mistakes.

None of the options given sit right with me though.

-- 
Adam Olsen, aka Rhamphoryncus



More information about the Python-ideas mailing list