context: explicitly tests for None
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Wed, 15 Mar 2017 15:33:24 -0700
changeset 31446 084050d76e4f
parent 31445 ac7aa96e4cd8
child 31447 82350f7fa56c
context: explicitly tests for None Changeset 9e57033fec0c removed the mutable default value, but did not explicitly tested for None. Such implicit testing can introduce semantic and performance issue. We move to an explicit testing for None as recommended by PEP8: https://www.python.org/dev/peps/pep-0008/#programming-recommendations
mercurial/context.py
--- a/mercurial/context.py	Wed Mar 15 15:11:52 2017 -0700
+++ b/mercurial/context.py	Wed Mar 15 15:33:24 2017 -0700
@@ -300,8 +300,10 @@
 
     def match(self, pats=None, include=None, exclude=None, default='glob',
               listsubrepos=False, badfn=None):
+        if pats is None:
+            pats = []
         r = self._repo
-        return matchmod.match(r.root, r.getcwd(), pats or [],
+        return matchmod.match(r.root, r.getcwd(), pats,
                               include, exclude, default,
                               auditor=r.nofsauditor, ctx=self,
                               listsubrepos=listsubrepos, badfn=badfn)
@@ -1517,16 +1519,18 @@
 
     def match(self, pats=None, include=None, exclude=None, default='glob',
               listsubrepos=False, badfn=None):
+        if pats is None:
+            pats = []
         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 or [],
+            return matchmod.icasefsmatcher(r.root, r.getcwd(), pats,
                                            include, exclude, default, r.auditor,
                                            self, listsubrepos=listsubrepos,
                                            badfn=badfn)
-        return matchmod.match(r.root, r.getcwd(), pats or [],
+        return matchmod.match(r.root, r.getcwd(), pats,
                               include, exclude, default,
                               auditor=r.auditor, ctx=self,
                               listsubrepos=listsubrepos, badfn=badfn)