[Pkg-exppsy-maintainers] Why we should not use empty lists or dictionaries

Per B. Sederberg persed at princeton.edu
Wed Feb 13 02:43:45 UTC 2008


Hi folks:

After chatting with Greg, it's become quite clear why we were getting
the error in NiftiDataset.  The reason is that a default value for a
keyword argument is analyzed only once.  For mutable objects like
lists and dictionaries, this means that those objects stick around for
each subsequent call of the method.  See the Important Note on this
webpage:

http://www.network-theory.co.uk/docs/pytut/DefaultArgumentValues.html

So, I think in almost every case in pymvpa we need to switch over to
using None as the default value and then to set the value to a new
dict or list if we want.  Granted, there may be some cases that I did
not see where you would actually want the strange recursive behavior
that evolves from using an empty list or dictionary as the default
value.  I contend we never want to use it in any __init__ of a class.

Best,
Per



More information about the Pkg-exppsy-maintainers mailing list