Skip to content

toc_object_entries uses language (Python) scoping instead of documentation scoping #12352

Closed
@jakobandersen

Description

@jakobandersen

Describe the bug

The entries added by toc_object_entries for Python (and other domains?) seems to use the scoping of the language to nest the toc entries, instead of how they were declared in the document. E.g., if a nested class is declared after the class, then its entry is nested inside the class instead of appended.

How to Reproduce

E.g., with

.. py:currentmodule:: myMod
.. py:class:: MyClass

	.. py:method:: f()

.. py:class:: MyClass.MyNestedClass

I get the toc

- MyClass
  - MyClass.f()
  - MyClass.MyNestedClass

instead of

- MyClass
  - MyClass.f()
- MyClass.MyNestedClass

Environment Information

Tested with current master.

Sphinx extensions

No response

Additional context

Could the check at

if parents and parents in memo_parents:
be changed to check if the parent in the language is also the parent in the current toctree generation?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions