changeset 31388:9e57033fec0c

context: don't use mutable default argument value Mutable default argument values are a Python gotcha and can represent subtle, hard-to-find bugs. Lets rid our code base of them.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 12 Mar 2017 21:50:42 -0700
parents 3d3109339b57
children 758526333dec
files mercurial/context.py
diffstat 1 files changed, 7 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/context.py	Mon Mar 13 11:19:24 2017 -0700
+++ b/mercurial/context.py	Sun Mar 12 21:50:42 2017 -0700
@@ -298,10 +298,10 @@
         '''
         return subrepo.subrepo(self, path, allowwdir=True)
 
-    def match(self, pats=[], include=None, exclude=None, default='glob',
+    def match(self, pats=None, include=None, exclude=None, default='glob',
               listsubrepos=False, badfn=None):
         r = self._repo
-        return matchmod.match(r.root, r.getcwd(), pats,
+        return matchmod.match(r.root, r.getcwd(), pats or [],
                               include, exclude, default,
                               auditor=r.nofsauditor, ctx=self,
                               listsubrepos=listsubrepos, badfn=badfn)
@@ -1515,18 +1515,18 @@
                     self._repo.dirstate.normallookup(dest)
                 self._repo.dirstate.copy(source, dest)
 
-    def match(self, pats=[], include=None, exclude=None, default='glob',
+    def match(self, pats=None, include=None, exclude=None, default='glob',
               listsubrepos=False, badfn=None):
         r = self._repo
 
         # Only a case insensitive filesystem needs magic to translate user input
         # to actual case in the filesystem.
         if not util.fscasesensitive(r.root):
-            return matchmod.icasefsmatcher(r.root, r.getcwd(), pats, include,
-                                           exclude, default, r.auditor, self,
-                                           listsubrepos=listsubrepos,
+            return matchmod.icasefsmatcher(r.root, r.getcwd(), pats or [],
+                                           include, exclude, default, r.auditor,
+                                           self, listsubrepos=listsubrepos,
                                            badfn=badfn)
-        return matchmod.match(r.root, r.getcwd(), pats,
+        return matchmod.match(r.root, r.getcwd(), pats or [],
                               include, exclude, default,
                               auditor=r.auditor, ctx=self,
                               listsubrepos=listsubrepos, badfn=badfn)