[PATCH 05 of 10] hgweb: don't use mutable default argument value

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


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1482796547 25200
#      Mon Dec 26 16:55:47 2016 -0700
# Node ID 1b0f806daa5e47cd88f6c1364cff06d96c1809db
# Parent  1575260785c1aedb72be38e6ff4303998b18ad90
hgweb: don't use mutable default argument value

diff --git a/mercurial/hgweb/common.py b/mercurial/hgweb/common.py
--- a/mercurial/hgweb/common.py
+++ b/mercurial/hgweb/common.py
@@ -88,14 +88,14 @@ def checkauthz(hgweb, req, op):
 permhooks = [checkauthz]
 
 
 class ErrorResponse(Exception):
-    def __init__(self, code, message=None, headers=[]):
+    def __init__(self, code, message=None, headers=None):
         if message is None:
             message = _statusmessage(code)
         Exception.__init__(self, message)
         self.code = code
-        self.headers = headers
+        self.headers = headers or []
 
 class continuereader(object):
     def __init__(self, f, write):
         self.f = f
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
@@ -57,11 +57,8 @@ New errors are not allowed. Warnings are
    use encoding.environ instead (py3)
   mercurial/exchange.py:1019:
    > def _localphasemove(pushop, nodes, phase=phases.public):
    attribute default argument value may be mutable
-  mercurial/hgweb/common.py:92:
-   >     def __init__(self, code, message=None, headers=[]):
-   mutable default argument value (list)
   mercurial/hgweb/webutil.py:145:
    >     def __init__(self, siblings=[], hiderev=None):
    mutable default argument value (list)
   Skipping mercurial/httpclient/__init__.py it has no-che?k-code (glob)


More information about the Mercurial-devel mailing list