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

No member information generated for exceptions #162

Open
rra opened this issue Apr 12, 2023 · 4 comments
Open

No member information generated for exceptions #162

rra opened this issue Apr 12, 2023 · 4 comments
Labels

Comments

@rra
Copy link

rra commented Apr 12, 2023

I'm working on a code base that often defines methods (both class and instance) on exceptions. The class methods are used to construct the exception from other data (often other underlying exceptions), and the instance methods are used to format the exceptions for reporting to external systems.

It looks like sphinx-automodapi doesn't generate method information for exceptions, and I didn't see any documented way to enable this. For example, an exception class with a to_slack instance method and a from_exception class method generates only:

SlackWebException
=================

.. currentmodule:: safir.slack.blockkit

.. autoexception:: SlackWebException

I was hoping there would be some way to enable the normal sort of class documentation, such as:

SlackWebException
=================

.. currentmodule:: safir.slack.blockkit

.. autoexception:: SlackWebException

   .. rubric:: Methods Summary

   .. autosummary::

      ~SlackWebException.from_exception
      ~SlackWebException.to_slack

   .. rubric:: Methods Documentation

   .. automethod:: from_exception
   .. automethod:: to_slack
@pllim
Copy link
Member

pllim commented Apr 12, 2023

According to https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#directive-autoexception , it "will by default only insert the docstring of the object itself". If you want methods includes, you have to provide extra directives. That is from Sphinx proper, I don't think this is strictly related to sphinx-automodapi ? I could have misunderstood your problem though. Can you please clarify? Thanks!

@rra
Copy link
Author

rra commented Apr 12, 2023

The second example in my bug report is the rST code that sphinx-automodapi generates for a regular class, so I don't think it's relying on any special support in Sphinx for generating the method summary. It's generating rST specifying which methods for which to generate documentation.

What I would like it to do is the same thing for exceptions. Currently, apparently exceptions are special-cased to not get the method summary of other classes.

I suspect the problem may be that there is no template for exceptions, and therefore the code here:

tmplstr = 'autosummary_core/%s.rst'

falls back on the base template, which doesn't include a method summary. I would get the behavior that I want if a template like the class template were used instead, I think (although there are probably complications that I'm not yet seeing). Although I'm not 100% sure I found the correct code, since the rST generated for an exception doesn't quite match any of the templates.

@pllim
Copy link
Member

pllim commented Apr 12, 2023

We currently do not have resources to maintain this much, so if you really want this fixed, feel free to submit a PR, or not use automodapi for that section. Thanks!

@parejkoj
Copy link

I'll ping this one, as I also have a custom exception with documented methods that don't show up in our output docs because of this:

This docstring and method:

https://github.com/lsst/pipe_base/blob/fe85a52a0f82f086f2117950cdcd6b2501af1b7c/python/lsst/pipe/base/_status.py#L165

doesn't appear here in the output docs here:

https://pipelines.lsst.io/v/daily/py-api/lsst.pipe.base.AnnotatedPartialOutputsError.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants