Skip to content

autosummary: determine "canonical" name of the class in templateΒ #5589

@MarSoft

Description

@MarSoft

Subject: it is currently impossible to determine canonical class name from the template

Problem

  • When classes to be included in the summary are referenced by non-canonical paths, :show-inheritance: parameter for autoclass block produces code referencing the canonical name of the class, but {{ objname }} value is the non-canonical one.
  • As a result, the link to parent class in Bases: is broken and is not clickable.
  • If there would be an option to determine canonical name (myclass.__module__ + '.' + myclass.__name__) then I could include that as a TOC entry or something like that.

Procedure to reproduce the problem

I'll illustrate it with the following minimum example:

# mypkg/__init__.py
from .parent import Parent
from .child import Child
# mypkg/parent.py
class Parent:
    pass
# mypkg/child.py
from .parent import Parent
class Child(Parent):
    pass
# docs/_templates/autosummary/class.rst
{{ fullname | escape | underline }}

.. autoclass:: {{objname}}
   :show-inheritance:
   :members:
# docs/index.rst
.. autosummary::
   :toctree: _autosummary

   mypkg.Parent
   mypkg.Child

Error logs / results

  • Build the docs and observe that class referenced as mypkg.Child is displayed as so, but its base class is listed as mypkg.parent.Parent and it not clickable.

Expected results

It should be possible to determine canonical class name, or class' actual module name.
For now, template variable module is derieved from the textual name given as the input. It is not currently possible to access myobject.__module__.

Environment info

  • OS: Arch Linux
  • Python version: 3.6, 3.7
  • Sphinx version: Sphinx==1.8.0

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions