changeset 26311:60dd8e3977f0

util: avoid mutable default arguments I almost introduced a bug around this code by accidentally mutating a default argument. There's no reason for these to exist.
author Siddharth Agarwal <sid0@fb.com>
date Tue, 22 Sep 2015 16:55:18 -0700
parents 61efe9ef6ad4
children 60558319ce72
files mercurial/util.py
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/util.py	Sun Sep 13 18:01:01 2015 +0900
+++ b/mercurial/util.py	Tue Sep 22 16:55:18 2015 -0700
@@ -730,7 +730,7 @@
     global _hgexecutable
     _hgexecutable = path
 
-def system(cmd, environ={}, cwd=None, onerr=None, errprefix=None, out=None):
+def system(cmd, environ=None, cwd=None, onerr=None, errprefix=None, out=None):
     '''enhanced shell command execution.
     run with environment maybe modified, maybe in different dir.
 
@@ -739,6 +739,8 @@
 
     if out is specified, it is assumed to be a file-like object that has a
     write() method. stdout and stderr will be redirected to out.'''
+    if environ is None:
+        environ = {}
     try:
         sys.stdout.flush()
     except Exception:
@@ -1414,7 +1416,7 @@
         unixtime = localunixtime + offset
     return unixtime, offset
 
-def parsedate(date, formats=None, bias={}):
+def parsedate(date, formats=None, bias=None):
     """parse a localized date/time and return a (unixtime, offset) tuple.
 
     The date may be a "unixtime offset" string or in one of the specified
@@ -1434,6 +1436,8 @@
     >>> tz == strtz
     True
     """
+    if bias is None:
+        bias = {}
     if not date:
         return 0, 0
     if isinstance(date, tuple) and len(date) == 2: