config: avoid using a mutable default

Augie Fackler raf at durin42.com
Sun Mar 12 18:53:31 EDT 2017


On Sun, Mar 12, 2017 at 12:56:20PM -0700, Martijn Pieters wrote:
> # HG changeset patch
> # User Martijn Pieters <mjpieters at 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()


More information about the Mercurial-devel mailing list