Patchwork [8,of,8] context: explicitly tests for None

login
register
mail settings
Submitter Pierre-Yves David
Date March 16, 2017, 11:28 a.m.
Message ID <d912b21f4721d399fd32.1489663692@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/19389/
State Accepted
Headers show

Comments

Pierre-Yves David - March 16, 2017, 11:28 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1489617204 25200
#      Wed Mar 15 15:33:24 2017 -0700
# Node ID d912b21f4721d399fd327b6bb7179de7e2a614b6
# Parent  414372f08c44186c8dad9dea46d617ab61412503
# EXP-Topic mutable-default
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
#              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r d912b21f4721
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

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -300,8 +300,10 @@  class basectx(object):
 
     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 @@  class workingctx(committablectx):
 
     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)