Sphinx: `autodoc_member_order = 'bysource'` does not work for modules containing __all__

Created on 26 Apr 2017  路  4Comments  路  Source: sphinx-doc/sphinx

Subject: autodoc_member_order = 'bysource' does not work for modules containing __all__

Problem

When setting autodoc_member_order to 'bysource' in conf.py, it does not work entirely as expected on modules that contain __all__. The members are listed in the order dictated by __all__, which is expected. But the members of the members are listed alphabetically.

Procedure to reproduce the problem

- I have a module `foo` in `foo/__init__.py`
- `__init__.py` itself contains no code other than import
  statements from private modules
  (e.g., `from ._bar import spam, eggs`)
- `__init__.py` has a line that says `__all__ = ['spam', 'eggs']`
- `spam`, in this scenario, is a class that contains two
  methods in this order: `b` and `a`.
- Apply Sphinx magic.
- Module foo in Sphinx is listed in this order:
  - spam
    - a
    - b
  - eggs

Error logs / results

N/A

Expected results

b and a should be swapped.

Reproducible project / your project

Environment info

  • OS: Debian Stretch
  • Python version: 3.5.3
  • Sphinx version: 1.5.3
autodoc bug

All 4 comments

I have _almost_ the same issue:

  • I'm working on a module
  • __init__.py only contains Docstring and imports
  • __init__.py does not have an __all__ assignment
  • I have the line autodoc_member_order = 'bysource' at the end of my conf.py
  • Class functions are ordered alphabetically...

Environment info

OS: macOS 10.12.6
Python version: 3.6.1
Sphinx version: 1.6.2

I'm working on a package, there is nothing in __init__.py.
When I add the line autodoc_member_order = 'bysource' in my conf.py, in the documentation some modules are still ordered alphabetically. I can't find why some of them are well ordered by source and some of them aren't. It seems that the problem occurs more when a module contains class declaration.

Environment info

  • OS: Windows 10
  • Python version: 2.7.13
  • Sphinx version: 1.6.3

The comment https://github.com/sphinx-doc/sphinx/issues/2042#issuecomment-203033366 suggests bysource fails if Sphinx failed to parse the Python code, which might be related to the pattern you are seeing?

bysource fails if Sphinx failed to parse the Python code, which might be related to the pattern you are seeing?

I've seen this happen for class definitions where cls.__module__ is overloaded, as this results in inspect.getsource failing.

Was this page helpful?
0 / 5 - 0 ratings