Repository navigation
Description
Problem
autodoc_default_flags
This value is a list of autodoc directive flags that should be automatically applied to all autodoc directives. The supported flags are 'members', 'undoc-members', 'private-members', 'special-members', 'inherited-members' and 'show-inheritance'.
I want to be able to set values in conf.py equivalent to adding additional configuration entries under :autodoc: including some which have arguments, including sorting members according to the source code, e.g.:
:member-order: bysource
:special-members: __init__
:exclude-members: __dict__,__weakref__
While member order seems to be covered specifically via autodoc_member_order = ... in conf.py, this seems to be a special case: http://www.sphinx-doc.org/en/stable/ext/autodoc.html#confval-autodoc_member_order
In general it seems I cannot give optional arguments to autodoc flags via conf.py.
See also #4057, cannot give optional arguments to autodoc flags via sphinx-apidoc
Procedure to reproduce the problem
Reading the code, these are the only possible flags which can be given using autodoc_default_flags = [...] in conf.py, this is missing member-order and exclude-members which I want to use.
# flags that can be given in autodoc_default_flags
_default_flags = set([
'members', 'undoc-members', 'inherited-members', 'show-inheritance',
'private-members', 'special-members',
])Moreover, the values from the conf.py file's autodoc_default_flags = ... entry are treated as a simple list - there is no scope for arguments:
Expected results
I can achieve the desired results by editing the sphinx-apidoc generated RST files before running Sphinx, but I wanted to avoid this step via configuration instead.
One suggested syntax, either allow a list/tuple/set as now:
autodoc_default_flags = ['members', 'undoc-members', 'special-members', 'show-inheritance']
Or, a dict where keys are a string giving the arguments, and I suggest the empty string or None if no arguments are needed:
autodoc_default_flags = {
'members' : 'eat,slurp', 'undoc-members' : '',
'special-members': '__init__',
'show-inheritance': '',
'member-order': 'bysource',
'exclude-members': '__dict__,__weakref__'
}This would mean autodoc_member_order becomes a special case legacy alternative for member-order
Alternatively, supplement autodoc_member_order with extra settings like autodoc_exclude_members and autodoc_special_members etc for those which support arguments?
Activity
peterjc commentedon Oct 10, 2017
The team's preference is new settings in
conf.pylikeautodoc_exclude_membersandautodoc_special_memberstaking lists - hopefully #4076 will be merged to implement this.peterjc commentedon Mar 12, 2018
According to #4076 (comment) @shimizukawa likes the idea of extending
autodoc_default_flagsto allow a dict of default settings.Fix sphinx-doc#4075: autodoc: autodoc_default_flags allows dict style…
Fix sphinx-doc#4075: autodoc: autodoc_default_flags allows dict style…
Fix sphinx-doc#4075: autodoc: autodoc_default_flags allows dict style…
Fix sphinx-doc#4075: autodoc: autodoc_default_flags allows dict style…
tk0miya commentedon Aug 18, 2018
Now
autodoc_default_flagsaccepts dict styled settings by #5215.Thanks for @LewisHaley!