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.
--- 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: