Patchwork config: avoid using a mutable default

login
register
mail settings
Submitter Martijn Pieters
Date March 12, 2017, 7:56 p.m.
Message ID <22c38e571b5ccf3bb6d9.1489348580@mjpieters-mbp>
Download mbox | patch
Permalink /patch/19230/
State Accepted
Headers show

Comments

Martijn Pieters - March 12, 2017, 7:56 p.m.
# HG changeset patch
# User Martijn Pieters <mjpieters@fb.com>
# Date 1489348572 25200
#      Sun Mar 12 12:56:12 2017 -0700
# Node ID 22c38e571b5ccf3bb6d9f075526170954843f37a
# Parent  719e64bf9ec2d7b8e86b6550a5d193b3c67944d1
config: avoid using a mutable default

Nothing *currently* mutates this list, but the moment something does it'll be
shared between all config instances. Avoid this eventuality.
Augie Fackler - March 12, 2017, 10:53 p.m.
On Sun, Mar 12, 2017 at 12:56:20PM -0700, Martijn Pieters wrote:
> # HG changeset patch
> # User Martijn Pieters <mjpieters@fb.com>
> # Date 1489348572 25200
> #      Sun Mar 12 12:56:12 2017 -0700
> # Node ID 22c38e571b5ccf3bb6d9f075526170954843f37a
> # Parent  719e64bf9ec2d7b8e86b6550a5d193b3c67944d1
> config: avoid using a mutable default

Queued, thanks.

>
> Nothing *currently* mutates this list, but the moment something does it'll be
> shared between all config instances. Avoid this eventuality.
>
> diff --git a/mercurial/config.py b/mercurial/config.py
> --- a/mercurial/config.py
> +++ b/mercurial/config.py
> @@ -18,11 +18,11 @@
>  )
>
>  class config(object):
> -    def __init__(self, data=None, includepaths=[]):
> +    def __init__(self, data=None, includepaths=None):
>          self._data = {}
>          self._source = {}
>          self._unset = []
> -        self._includepaths = includepaths
> +        self._includepaths = includepaths or []
>          if data:
>              for k in data._data:
>                  self._data[k] = data[k].copy()

Patch

diff --git a/mercurial/config.py b/mercurial/config.py
--- a/mercurial/config.py
+++ b/mercurial/config.py
@@ -18,11 +18,11 @@ 
 )
 
 class config(object):
-    def __init__(self, data=None, includepaths=[]):
+    def __init__(self, data=None, includepaths=None):
         self._data = {}
         self._source = {}
         self._unset = []
-        self._includepaths = includepaths
+        self._includepaths = includepaths or []
         if data:
             for k in data._data:
                 self._data[k] = data[k].copy()