[PATCH 3 of 4] util: avoid mutable default arguments
Siddharth Agarwal
sid0 at fb.com
Wed Sep 23 00:15:22 UTC 2015
# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1442966118 25200
# Tue Sep 22 16:55:18 2015 -0700
# Node ID 2e9d6b73a2a88c044175a05d32626b18afc0e889
# Parent c10a294cdec22c49568da7863745085b19d846f7
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.
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -730,7 +730,7 @@ def _sethgexecutable(path):
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 @@ def system(cmd, environ={}, cwd=None, on
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 @@ def strdate(string, format, defaults=[])
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 @@ def parsedate(date, formats=None, bias={
>>> tz == strtz
True
"""
+ if bias is None:
+ bias = {}
if not date:
return 0, 0
if isinstance(date, tuple) and len(date) == 2:
More information about the Mercurial-devel
mailing list