Use generator instead of default for libbe.bug.Bug.extra_strings.
authorW. Trevor King <wking@drexel.edu>
Tue, 23 Jun 2009 23:59:50 +0000 (19:59 -0400)
committerW. Trevor King <wking@drexel.edu>
Tue, 23 Jun 2009 23:59:50 +0000 (19:59 -0400)
This avoids the problems associated with mutable defaults.

libbe/bug.py

index 89c02665ecc719d9f7631fbce942691cb298be89..0f912cf0c3a401dd6012fbb74d491471523e3d26 100644 (file)
@@ -185,6 +185,8 @@ class Bug(settings_object.SavedSettingsObject):
                     fset=_set_time,
                     doc="An integer version of .time_string")
 
+    def _extra_strings_generator(self):
+        return []
     def _extra_strings_check_fn(value):
         "Require an iterable full of strings"
         if not hasattr(value, "__iter__"):
@@ -198,7 +200,7 @@ class Bug(settings_object.SavedSettingsObject):
         self._prop_save_settings(old, new)
     @_versioned_property(name="extra_strings",
                          doc="Space for an array of extra strings.  Useful for storing state for functionality implemented purely in becommands/<some_function>.py.",
-                         default=[],
+                         generator=_extra_strings_generator,
                          check_fn=_extra_strings_check_fn,
                          change_hook=_extra_strings_change_hook,
                          mutable=True)