[Python-ideas] Default arguments in Python - the return - running out of ideas but...

Curt Hagenlocher curt at hagenlocher.org
Fri May 15 17:52:44 CEST 2009


On Fri, May 15, 2009 at 5:59 AM, George Sakkis <george.sakkis at gmail.com> wrote:
>
> More to the point, immutability is *not* the issue as Steven D'Aprano
> showed. There are perfectly legitimate reasons for using a default
> value that just happens to be mutable, without mutating it in the
> function body though. Dict is the most common example (especially
> since there is no frozendict type that could be used in its place).

There seem to be two separate "wants" that relate to this topic:

1. Preventing the "noob" mistake of saying "def f(x = {})" and
expecting that a new empty dictionary will be produced for each call,
and
2. Creating a more concise syntax for saying
def f(x = UNDEF):
    if x is UNDEF:
        x = {}

So far, the discussion seems to have revolved entirely around the
second request -- which I find by far less compelling than the first;
it's simply not a painful-enough pattern to warrant a special bit of
syntax. Furthermore, it doesn't do anything to address the first
desire.

--
Curt Hagenlocher
curt at hagenlocher.org



More information about the Python-ideas mailing list