Skip to content

limitations to autodoc_default_flags in conf.py #4075

Closed

Description

@peterjc

Problem

http://www.sphinx-doc.org/en/stable/ext/autodoc.html#confval-autodoc_default_flags says:

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',
    ])

Source: https://github.com/sphinx-doc/sphinx/blob/1.6.3/sphinx/ext/autodoc.py#L1769

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:

https://github.com/sphinx-doc/sphinx/blob/1.6.3/sphinx/ext/autodoc.py#L1812

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

  1. peterjc commented on Oct 10, 2017

    @peterjc
    ContributorAuthor

    The team's preference is new settings in conf.py like autodoc_exclude_members and autodoc_special_members taking lists - hopefully #4076 will be merged to implement this.

  2. peterjc commented on Mar 12, 2018

    @peterjc
    ContributorAuthor

    According to #4076 (comment) @shimizukawa likes the idea of extending autodoc_default_flags to allow a dict of default settings.

  3. added 4 commits that reference this issue on Aug 7, 2018
    ebe01a7
    716c230
    2aec002
    a2e8eb6
  4. tk0miya commented on Aug 18, 2018

    @tk0miya
    Member

    Now autodoc_default_flags accepts dict styled settings by #5215.
    Thanks for @LewisHaley!

  5. added this to the 1.8.0 milestone on Aug 18, 2018
  6. locked as resolved and limited conversation to collaborators on Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions