[PATCH 04 of 10] filemerge: don't use mutable default argument value

Pierre-Yves David pierre-yves.david at ens-lyon.org
Tue Dec 27 05:03:48 EST 2016



On 12/27/2016 01:03 AM, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc at gmail.com>
> # Date 1482796473 25200
> #      Mon Dec 26 16:54:33 2016 -0700
> # Node ID 1575260785c1aedb72be38e6ff4303998b18ad90
> # Parent  10645505563a162bb6d91a90e8b3ded769dcdbb1
> filemerge: don't use mutable default argument value
>
> diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
> --- a/mercurial/filemerge.py
> +++ b/mercurial/filemerge.py
> @@ -34,10 +34,10 @@ def _toolstr(ui, tool, part, default="")
>
>  def _toolbool(ui, tool, part, default=False):
>      return ui.configbool("merge-tools", tool + "." + part, default)
>
> -def _toollist(ui, tool, part, default=[]):
> -    return ui.configlist("merge-tools", tool + "." + part, default)
> +def _toollist(ui, tool, part, default=None):
> +    return ui.configlist("merge-tools", tool + "." + part, default or [])

Same feedback about testing for None or using ().

>  internals = {}
>  # Merge tools to document.
>  internalsdoc = {}
> 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/filemerge.py:38:
> -   > def _toollist(ui, tool, part, default=[]):
> -   mutable default argument value (list)
>    mercurial/hgweb/common.py:92:
>     >     def __init__(self, code, message=None, headers=[]):
>     mutable default argument value (list)
>    mercurial/hgweb/webutil.py:145:
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>

-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list