[PATCH 07 of 10] match: don't use mutable default argument value

Gregory Szorc gregory.szorc at gmail.com
Mon Dec 26 19:03:13 EST 2016


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1482796689 25200
#      Mon Dec 26 16:58:09 2016 -0700
# Node ID 95a432e534c28e14ff776cba0de355f5f6cb42dd
# Parent  cdb830b22b187debced54bd0d6e11e932bd7fdad
match: don't use mutable default argument value

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -84,9 +84,9 @@ def _kindpatsalwaysmatch(kindpats):
             return False
     return True
 
 class match(object):
-    def __init__(self, root, cwd, patterns, include=[], exclude=[],
+    def __init__(self, root, cwd, patterns, include=None, exclude=None,
                  default='glob', exact=False, auditor=None, ctx=None,
                  listsubrepos=False, warn=None, badfn=None):
         """build an object to match a set of file patterns
 
@@ -113,8 +113,10 @@ class match(object):
         'subinclude:<path>' - a file of patterns to match against files under
                               the same directory
         '<something>' - a pattern of the specified default type
         """
+        include = include or []
+        exclude = exclude or []
 
         self._root = root
         self._cwd = cwd
         self._files = [] # exact files and roots of patterns
diff --git a/tests/test-check-code.t b/tests/test-check-code.t
--- a/tests/test-check-code.t
+++ b/tests/test-check-code.t
@@ -59,12 +59,8 @@ New errors are not allowed. Warnings are
    > def _localphasemove(pushop, nodes, phase=phases.public):
    attribute default argument value may be mutable
   Skipping mercurial/httpclient/__init__.py it has no-che?k-code (glob)
   Skipping mercurial/httpclient/_readers.py it has no-che?k-code (glob)
-  mercurial/match.py:88:
-   >     def __init__(self, root, cwd, patterns, include=[], exclude=[],
-   mutable default argument value (list)
-   mutable default argument value (list)
   mercurial/policy.py:45:
    > policy = os.environ.get('HGMODULEPOLICY', policy)
    use encoding.environ instead (py3)
   Skipping mercurial/statprof.py it has no-che?k-code (glob)


More information about the Mercurial-devel mailing list