Merge lp:~allenap/maas/fix-mutable-argument-defaults into lp:~maas-committers/maas/trunk
Status: | Merged |
---|---|
Approved by: | Gavin Panella |
Approved revision: | no longer in the source branch. |
Merged at revision: | 5874 |
Proposed branch: | lp:~allenap/maas/fix-mutable-argument-defaults |
Merge into: | lp:~maas-committers/maas/trunk |
Diff against target: |
218 lines (+78/-70) 4 files modified
src/maasserver/forms/ephemeral.py (+2/-1) src/provisioningserver/drivers/pod/__init__.py (+9/-7) src/provisioningserver/drivers/storage/__init__.py (+3/-3) src/provisioningserver/logger/testing/logsomething.py (+64/-59) |
To merge this branch: | bzr merge lp:~allenap/maas/fix-mutable-argument-defaults |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Mike Pontillo (community) | Approve | ||
Review via email: mp+321300@code.launchpad.net |
Commit message
Replace mutable arguments.
Description of the change
Mutable arguments are generally a bad thing. One pattern in particular
has appeared in MAAS; here's a reduced example:
@attr.s
class DiscoveredMachi
tags = attr.ib(
The problem here is that every new instance will share the same initial
list of tags.
>>> dmi = DiscoveredMachi
>>> dmi.tags.
>>> dmi
DiscoveredMac
mac_
>>> dmi2 = DiscoveredMachi
>>> dmi2
DiscoveredMac
mac_
The fix here is to use a default *factory*:
tags = attr.ib(
I discovered these problems using findmutargs.py from:
lp:~allenap/+junk/find-bad-argument-defaults
The change in this branch to `logsomething.py` was made entirely to
allow `findmutargs.py` to load it without setting it off.
Looks good.