Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
MarSoft opened this issue Nov 3, 2018 · 5 comments
Closed

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

MarSoft opened this issue Nov 3, 2018 · 5 comments

Comments

@MarSoft
Copy link

MarSoft commented Nov 3, 2018

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
@MuellerSeb
Copy link

I ran into the same problem!

@tk0miya
Copy link
Member

tk0miya commented Jan 25, 2020

Indeed, this is broken. +1 to give canonical name (alias name?).

@tk0miya tk0miya modified the milestones: 3.0.0, 3.1.0 Mar 14, 2020
@tk0miya tk0miya modified the milestones: 3.1.0, 3.2.0 May 30, 2020
@tk0miya tk0miya modified the milestones: 3.2.0, 4.0.0 Jul 18, 2020
@MuellerSeb
Copy link

Anything new here?
One solution could be to provide an alias_overrides dictionary in conf.py where you can redirect links like it is done in scanpydoc:
https://icb-scanpydoc.readthedocs-hosted.com/en/latest/scanpydoc.elegant_typehints.html

@flying-sheep
Copy link
Contributor

flying-sheep commented Feb 1, 2021

An actual fix is in the works, but still not ready: #8449

@cblegare are you going to finish that or are there some blockers?

@tk0miya
Copy link
Member

tk0miya commented Mar 27, 2021

Now I merged #9026 that generates :canonical: option for the imported classes (instead of #8449). It allows to refer the python objects by its canonical name.
Thanks!

@tk0miya tk0miya closed this as completed Mar 27, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants