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

Jim Jewett jimjjewett at gmail.com
Tue Jan 30 18:22:01 CET 2007


On 1/30/07, Jan Kanis <jan.kanis at phil.uu.nl> wrote:
> On Tue, 30 Jan 2007 08:19:11 +0100, Jim Jewett <jimjjewett at gmail.com>
> wrote:
> > On 1/30/07, Chris Rebert <cvrebert at gmail.com> wrote:
> >> Also, due to the
> >> hairiness/obscurity of the construct, hardly anyone uses it, so the
> >> impact of removing it should be relatively minor.

> > I just did found 181 such uses in my own installation.  29 were either
> > 3rd-party or test code, but that still leaves over 150 uses in the
> > standard library.  It is possible that some of them would also work
> > with your semantics, or may even be bugs today -- but you would have
> > to go through them one-by-one as part of the PEP process.

> But that's certainly possible. What exactly did you search for, and what
> did you find?

In idle, edit menu, find in files, regex 'def.*=(\\[|\\{)(\\]|\\})'

In other words, it caught "={}" or "=[]" on a def line.

It did not catch other (possibly mutable) default args, nor did it
catch multi-line definitions, nor did it even catch extra whitespace.
I didn't notice any false positives where the "={}" was really in a
comment.

I didn't even look at defaults of None (let alone other singletons) to
see if they were part of this idiom.

They mostly seemed to be passing state, but the __init__ methods in
particular may have been using a class-level variable by accident.
(such as the cnf argument to Tk widgets.)  I'll try to check more
closely later.

-jJ



More information about the Python-ideas mailing list