[patch] make 'bzr ignore' take multiple arguments (bug 29488)

Andrew Bennetts andrew at canonical.com
Tue Oct 10 09:59:35 BST 2006


Cheuksan Edward Wang wrote:
[...]
> -    def run(self, name_pattern=None, old_default_rules=None):
> +    def run(self, name_pattern_list=[], old_default_rules=None):

It's a good idea to avoid using mutable values as default argument defintions.
If the function is called more than once, and happens to modify the value, then
you get surprising behaviour.

In this case it probably won't cause in problems, but it's an accident waiting
to happen -- a future refactoring of the code might innocently mutate
name_pattern_list without realising it's not safe.  It's a good habit to avoid
mutable args always.

Generally, you can instead default to None, and use "if name_pattern_list is
None: name_pattern_list = []" near the top of the function.

-Andrew.





More information about the bazaar mailing list