mutable default parameter problem [Prothon]

Marcin 'Qrczak' Kowalczyk qrczak at
Wed Jun 16 11:20:15 CEST 2004

On Tue, 15 Jun 2004 22:01:19 -0800, Troy Melhase wrote:

> $  find /usr/lib/python2.3/ -name "*.py" -exec grep "def.*=\[\]" {} \; | wc
> And see 67 instances just in the standard library.

I don't know how you counted them:

[qrczak ~/src/python/Python-2.3.4]$ egrep 'def.*= ?\[\]' **/*.py | wc -l
[qrczak ~/src/python/Python-2.3.4]$ egrep 'def.*= ?None' **/*.py | wc -l

Now consider that many of the Nones are a workaround for the current
Python behavior.

I agree that it's probably impractical to change Python rules because
some code relies on the current behavior. OTOH evaluating the default
argument each time when the function is applied is technically better.
This is one of warts which is hard to fix because of compatibility.

   __("<         Marcin Kowalczyk
   \__/       qrczak at

More information about the Python-list mailing list