Comment 6 for bug 140432

Revision history for this message
Aaron Bentley (abentley) wrote : Re: [Bug 140432] Re: bzr fails with 'iteration over non-sequence'

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

vila wrote:
> I encountered the same bug coming from a different path: I was trying to
> use a builtins.cmd_commit object without providing a 'fixes' parameter.
>
> Also Jan's fix is correct, I'd like to mention that the bug IMHO is in
> the default value for a ListOption ('fixes' is the only option of that
> type in bzr code base).
>
> --- bzrlib/builtins.py 2007-09-11 00:27:26 +0000
> +++ bzrlib/builtins.py 2007-09-13 16:58:05 +0000
> @@ -2251,7 +2257,7 @@
>
> def run(self, message=None, file=None, verbose=False, selected_list=None,
> - unchanged=False, strict=False, local=False, fixes=None,
> + unchanged=False, strict=False, local=False, fixes=[],
> author=None, show_diff=False):

An empty list should never be supplied as a default value, because list
is a mutable type. We don't want to open the door to the possibility
that this particular instance of the list will be changed.

While the empty tuple is similar to the empty list, the usual idiom is:

def foo(bar=None):
    if bar is None:
        bar = []

(It would be nice if a callable could be supplied as a default, rather
than an instance, because then we could do 'def foo(bar=list):' and
avoid the extra typing.

Aaron
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFG8DLn0F+nu1YWqI0RAllxAJ4yalEN+ldsOc5Us1EPO3O8ng+E/wCZAdHa
593mycM/GYyLtpoxAHfkRec=
=8s9I
-----END PGP SIGNATURE-----