dash/test/functional/test_framework
MarcoFalke a84ec5cc19 Merge #16726: tests: Avoid common Python default parameter gotcha when mutable dict/list:s are used as default parameter values
e4f4ea47ebf7774fb6f445adde7bf7ea71fa05a1 lint: Catch use of [] or {} as default parameter values in Python functions (practicalswift)
25dd86715039586d92176eee16e9c6644d2547f0 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 e4f4ea47ebf7774fb6f445adde7bf7ea71fa05a1. Testing tip: swap the two commits.

Tree-SHA512: 56e14d24fc866211a20185c9fdb274ed046c3aed2dc0e07699e58b6f9fa3b79f6d0c880fb02d72b7fe5cc5eb7c0ff6da0ead33123344e1a872209370c2e49e3f
2023-04-04 12:45:27 -05:00
..
__init__.py Merge bitcoin#9956: Reorganise qa directory (#2912) 2019-05-19 23:20:34 +03:00
address.py Merge #17984: test: Add p2p test for forcerelay permission 2022-10-20 11:48:12 -04:00
authproxy.py Merge #18596: test: Try once more when RPC connection fails on Windows 2021-09-28 14:46:44 -04:00
blocktools.py Merge #19082: test: Moved the CScriptNum asserts into the unit test in script.py 2023-02-27 23:12:41 -06:00
coverage.py Some Dashification (#3513) 2020-06-11 11:39:04 +03:00
descriptors.py merge bitcoin#15368: Descriptor checksums 2021-10-28 14:01:02 +05:30
key.py merge bitcoin#19105: Add Muhash3072 implementation in Python 2022-04-27 20:05:13 +05:30
messages.py Merge #16726: tests: Avoid common Python default parameter gotcha when mutable dict/list:s are used as default parameter values 2023-04-04 12:45:27 -05:00
mininode.py Merge #18807: [doc / test / mempool] unbroadcast follow-ups 2023-02-27 23:12:41 -06:00
muhash.py partial bitcoin#19055: Add MuHash3072 implementation 2022-04-27 20:05:13 +05:30
netutil.py Merge bitcoin/bitcoin#24342: test: remove import socket in test_ipv6_local 2022-04-11 09:46:40 -07:00
ripemd160.py docs/build: Kubuntu 22.04 build fix (#4843) 2022-05-28 23:27:04 -05:00
script_util.py Merge #18732: test: Remove unused, undocumented and misleading CScript.__add__ 2023-03-03 23:07:15 +05:30
script.py Merge #18732: test: Remove unused, undocumented and misleading CScript.__add__ 2023-03-03 23:07:15 +05:30
siphash.py Merge bitcoin#9956: Reorganise qa directory (#2912) 2019-05-19 23:20:34 +03:00
socks5.py merge #14954: Require python 3.5 2021-08-31 11:16:12 +05:30
test_framework.py Merge #18952: test: avoid os-dependant path 2023-04-02 17:00:24 -05:00
test_node.py Merge #19252: test: wait for disconnect in disconnect_p2ps + bloomfilter test followups 2023-02-27 23:12:41 -06:00
test_shell.py Merge #17378: TestShell: Fix typos & implement cleanups 2023-01-23 12:22:29 -06:00
util.py Merge #16598: test: Remove confusing hash256 function in util 2023-04-04 12:45:27 -05:00
wallet_util.py Merge #15108: [tests] tidy up wallet_importmulti.py 2022-03-08 22:53:13 -05:00