Default Value

Chris Angelico rosuav at gmail.com
Fri Jun 21 15:07:59 EDT 2013


On Sat, Jun 22, 2013 at 4:26 AM, Rick Johnson
<rantingrickjohnson at gmail.com> wrote:
> I could cast a "virtual net" over my poor lemmings before
> they jump off the cliff by throwing an exception:
>
>   Traceback (most recent screw-up last):
>    Line BLAH in SCRIPT
>     def f(x = [None, b, [a, [4]]]):
>   ArgumentError: No mutable default arguments allowed!

So tell me, oh Great and Powerful Wizard of Rick, how is the
interpreter supposed to know which defaults are mutable? I mean, it's
obviously some intrinsic property of the object. Somehow one thing is
clearly immutable, another thing clearly isn't. Will there be a
PyObject_IsImmutable() API?

Oh! I know. Function argument defaults will now be restricted to
int/float/tuple. That would do it, right? Nobody would be bothered by
little restrictions like that, would they.

ChrisA



More information about the Python-list mailing list