From 87029392fd73521a3d25e3ceba363c19d93a3c7a Mon Sep 17 00:00:00 2001 From: Lewis Haley Date: Thu, 26 Jul 2018 11:43:28 +0100 Subject: [PATCH] test_autodoc: fix mutable function default argument in do_autodoc Setting mutable types as default arguments is bad practice because the value is only initialised once. This means that defaults arguments of lists and dictionaries which are modified during code execution *stay* modified between calls. In this case, the `options` dictionary accumulated options as more and more test cases were executed. Without this change, the tests added in the next commit do not pass. See: https://stackoverflow.com/questions/1132941/least-astonishment-and-the-mutable-default-argument --- tests/test_autodoc.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_autodoc.py b/tests/test_autodoc.py index d3e69766f..a54c9c2e6 100644 --- a/tests/test_autodoc.py +++ b/tests/test_autodoc.py @@ -34,7 +34,9 @@ else: ROGER_METHOD = ' .. py:classmethod:: Class.roger(a, e=5, f=6)' -def do_autodoc(app, objtype, name, options={}): +def do_autodoc(app, objtype, name, options=None): + if options is None: + options = {} doccls = app.registry.documenters[objtype] docoptions = process_documenter_options(doccls, app.config, options) bridge = DocumenterBridge(app.env, LoggingReporter(''), docoptions, 1)