HEADSUP default parameters

Robert Collins robertc at robertcollins.net
Tue May 9 04:01:44 BST 2006


I just got rid of the 'deleting paths' test stipple from bzrtools.

It was caused by a default parameter that is not None:

def foo(to_file=sys.stdout):
    # stuff here.


The reason this caused stipple is that the default parameter is
evaluated at compile time, causing any redirection to not take effect.

The correct way to do this is:

def foo(to_file=None):
    if to_file is None:
        to_file = sys.stdout


Similar bugs can be trigged by *any* default parameter other than None.

So this is a HEADSUP to code reviewers: please double-check that any
default parameter with a value of None is really what was intended.

Rob
-- 
GPG key available at: <http://www.robertcollins.net/keys.txt>.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060509/3b8902b7/attachment.pgp 


More information about the bazaar mailing list