[Python-ideas] Default arguments in Python - the return - running out of ideas but...
Terry Reedy
tjreedy at udel.edu
Fri May 15 21:33:13 CEST 2009
Curt Hagenlocher wrote:
> There seem to be two separate "wants" that relate to this topic:
Good observation.
> 1. Preventing the "noob" mistake of saying "def f(x = {})" and
> expecting that a new empty dictionary will be produced for each call,
> and
As a couple of us have suggested, this, like similar jobs, should be
handled by program checkers. I leave it to someone else to see if
existing programs already check and warn and, if not, suggest this to
their authors.
> 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.
The existing pattern explicitly says what one wants done. I suspect
editors with a macro facility could be given a macro to do most of the
boilerplate writing.
tjr
More information about the Python-ideas
mailing list