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
This commit is contained in:
Lewis Haley 2018-07-26 11:43:28 +01:00
parent 9cddc344db
commit 87029392fd

View File

@ -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)