[PATCHES] Dangerous default values



pylint warns about [] or {} being dangerous default values for method parameters
because all calls to the method will share a single instance, and if the method
modifies it, the others will see those modifications. And that is perhaps not
appropriate.

Please examine the attached 2 patches that fix 2 occurrences of the pattern.

-- 
Vincent Legoll
Index: gnomeglade.py
===================================================================
--- gnomeglade.py	(revision 1182)
+++ gnomeglade.py	(working copy)
@@ -36,10 +36,12 @@
     object, which is sadly sometimes necessary.
     """
 
-    def __init__(self, filename, root, override={}):
+    def __init__(self, filename, root, override=None):
         """Load the widgets from the node 'root' in file 'filename'.
         """
         gtk.glade.set_custom_handler(self.get_custom_handler)
+        if override is None:
+            override = {}
         self.xml = gtk.glade.XML(filename, root, typedict=override)
         self.xml.signal_autoconnect(self)
         self.widget = getattr(self, root)
Index: misc.py
===================================================================
--- misc.py	(révision 1182)
+++ misc.py	(copie de travail)
@@ -37,7 +37,7 @@
         return ((whitespace_re.search(s) == None) and s or ('"%s"' % s))
     return " ".join( [ quote(x) for x in command ] )
 
-def run_dialog( text, parent=None, messagetype=gtk.MESSAGE_WARNING, buttonstype=gtk.BUTTONS_OK, extrabuttons=[]):
+def run_dialog( text, parent=None, messagetype=gtk.MESSAGE_WARNING, buttonstype=gtk.BUTTONS_OK, extrabuttons=()):
     """Run a dialog with text 'text'.
        Extra buttons are passed as tuples of (button label, response id).
     """


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]