lbrycrd/test/functional/test_framework
MarcoFalke cc40b55da7
Merge #16726: tests: Avoid common Python default parameter gotcha when mutable dict/list:s are used as default parameter values
e4f4ea47eb lint: Catch use of [] or {} as default parameter values in Python functions (practicalswift)
25dd867150 Avoid using mutable default parameter values (practicalswift)

Pull request description:

  Avoid common Python default parameter gotcha when mutable `dict`/`list`:s are used as default parameter values.

  Examples of this gotcha caught during review:
  * https://github.com/bitcoin/bitcoin/pull/16673#discussion_r317415261
  * https://github.com/bitcoin/bitcoin/pull/14565#discussion_r241942304

  Perhaps surprisingly this is how mutable list and dictionary default parameter values behave in Python:

  ```
  >>> def f(i, j=[], k={}):
  ...     j.append(i)
  ...     k[i] = True
  ...     return j, k
  ...
  >>> f(1)
  ([1], {1: True})
  >>> f(1)
  ([1, 1], {1: True})
  >>> f(2)
  ([1, 1, 2], {1: True, 2: True})
  ```

  In contrast to:

  ```
  >>> def f(i, j=None, k=None):
  ...     if j is None:
  ...         j = []
  ...     if k is None:
  ...         k = {}
  ...     j.append(i)
  ...     k[i] = True
  ...     return j, k
  ...
  >>> f(1)
  ([1], {1: True})
  >>> f(1)
  ([1], {1: True})
  >>> f(2)
  ([2], {2: True})
  ```

  The latter is typically the intended behaviour.

  This PR fixes two instances of this and adds a check guarding against this gotcha going forward :-)

ACKs for top commit:
  Sjors:
    Oh Python... ACK e4f4ea47eb. Testing tip: swap the two commits.

Tree-SHA512: 56e14d24fc866211a20185c9fdb274ed046c3aed2dc0e07699e58b6f9fa3b79f6d0c880fb02d72b7fe5cc5eb7c0ff6da0ead33123344e1a872209370c2e49e3f
2019-08-28 13:34:31 -04:00
..
__init__.py Rename rpc-tests directory to functional 2017-03-20 10:40:31 -04:00
address.py test: Test p2sh-witness and bech32 in wallet_import_rescan 2019-08-14 17:20:07 -04:00
authproxy.py test: Properly log named args in authproxy 2019-04-08 18:38:54 -04:00
bignum.py Remove unused variables and/or function calls 2017-08-28 15:18:14 +02:00
blocktools.py test: Properly serialize BIP34 coinbase height 2019-07-09 14:12:33 -04:00
coverage.py Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
descriptors.py Descriptor checksum 2019-02-15 22:36:05 -08:00
key.py Add comments to Python ECDSA implementation 2019-04-18 13:23:26 -07:00
messages.py Avoid using mutable default parameter values 2019-08-26 10:45:25 +00:00
mininode.py test: Fail early on disconnect in mininode.wait_for_* 2019-07-26 16:11:26 -04:00
netutil.py scripted-diff: Update copyright in ./test 2019-03-02 10:58:35 -05:00
script.py scripted-diff: Update copyright in ./test 2019-03-02 10:58:35 -05:00
segwit_addr.py Use BIP173 addresses in segwit.py test 2017-09-28 17:29:01 -07:00
siphash.py Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
socks5.py scripted-diff: Update copyright in ./test 2019-03-02 10:58:35 -05:00
test_framework.py test: Adapt test framework for chains other than "regtest" 2019-07-31 17:00:25 -04:00
test_node.py QA: fix rpc_setban.py race 2019-08-21 14:18:40 +02:00
util.py Bugfix: QA: Run tests with UPnP disabled 2019-08-19 09:58:43 +08:00
wallet_util.py [tests] move wallet util functions to wallet_util.py 2019-01-04 17:49:17 -08:00