[PATCH 08 of 10] util: don't use mutable default argument value

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



On 12/27/2016 01:03 AM, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc at gmail.com>
> # Date 1482796746 25200
> #      Mon Dec 26 16:59:06 2016 -0700
> # Node ID f58ff64d5360ec1d82e3abb8ce8fdae8b3be3e9b
> # Parent  95a432e534c28e14ff776cba0de355f5f6cb42dd
> util: don't use mutable default argument value
>
> diff --git a/mercurial/util.py b/mercurial/util.py
> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -1804,11 +1804,13 @@ def parsetimezone(s):
>          return -sign * (hours * 60 + minutes) * 60, s[:-6]
>
>      return None, s
>
> -def strdate(string, format, defaults=[]):
> +def strdate(string, format, defaults=None):
>      """parse a localized time string and return a (unixtime, offset) tuple.
>      if the string cannot be parsed, ValueError is raised."""
> +    defaults = defaults or []

Same feedback about testing for None or using ().

> +
>      # NOTE: unixtime = localunixtime + offset
>      offset, date = parsetimezone(string)
>
>      # add missing elements from defaults
> 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
> @@ -63,11 +63,8 @@ New errors are not allowed. Warnings are
>    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)
> -  mercurial/util.py:1808:
> -   > def strdate(string, format, defaults=[]):
> -   mutable default argument value (list)
>    tests/run-tests.py:506:
>     >                  timeout=defaults['timeout'],
>     subscript default argument value may be mutable
>    tests/run-tests.py:507:
> _______________________________________________
> 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