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

Add support for documenting a subclass of param.Parameterized #13046

Closed
Davide-sd opened this issue Oct 20, 2024 · 1 comment
Closed

Add support for documenting a subclass of param.Parameterized #13046

Davide-sd opened this issue Oct 20, 2024 · 1 comment
Labels
type:proposal a feature suggestion

Comments

@Davide-sd
Copy link

Davide-sd commented Oct 20, 2024

Is your feature request related to a problem? Please describe.

One of param's main advantage is that of simplifying the codebase.

Let's consider this toy class:

import param

class A(param.Parameterized):
    """This is my docstring.
    """

    a = param.Boolean(True, doc="some docstring for parameter a")
    b = param.Number(1, bounds=(-10, 10), doc="some docstring for parameter b")
    c = param.Boolean(False, readonly=True, doc="some docstring for parameter c")
    d = param.ClassSelector(allow_None=True, class_=(list, tuple), doc="some docstring for parameter d")

    def __init__(self, a, b, **kwargs):
        super().__init__(a=a, b=b, **kwargs)

    def my_method(self):
        "my method docstring"
        pass

While working on Jupyter Notebook, I can read the class docstring with:

A?

which outputs:

Init signature: A(a, b, **kwargs)
Docstring:     
This is my docstring.
    
Parameters of 'A'
=================

Parameters changed from their default values are marked in red.
Soft bound values are marked in cyan.
C/V= Constant/Variable, RO/RW = ReadOnly/ReadWrite, AN=Allow None

Name Value       Type        Bounds     Mode  

a    True     Boolean                  V RW  
b     1        Number     (-10, 10)    V RW  
c   False     Boolean                  C RO  
d    None  ClassSelector             V RW AN 

Parameter docstrings:
=====================

a: some docstring for parameter a
b: some docstring for parameter b
c: some docstring for parameter c
d: some docstring for parameter d
Type:           ParameterizedMetaclass
Subclasses:       

This is great, because we can immediatly understand what parameters are available and what they are supposed to do.

However, we may need to create an html documentation (with Sphinx) of a module containing subclasses of param.Parameterized. So far, I tried Sphinx autodoc. In the file my_module.rst I wrote:

.. module:: my_module

.. autoclass:: A

..     autoattribute:: my_module.A.a
..     autoattribute:: my_module.A.b
..     autoattribute:: my_module.A.c
..     autoattribute:: my_module.A.d
..     autofunction:: my_module.A.my_method

However, autoattribute is unable to extract the docstring from the parameters.

Describe the solution you'd like

I realize this is a big feature request. The problem of documenting subclasses of param.Parameterized can be tackled in several ways, each one offering its own advantage and requiring a certain amount of effort to be coded.

The first one: let autoattribute be aware of param. This would allow a user to document only attributes that are supposed to be used by the user, while keeping other attributes as private.

In a basic form, autoattribute should be able to extract the docstring from the parameter. In a more advanced form, it would be nice to be able to chose what to display. Parameters encode some type. For example, a is a boolean, b represents a number whose value is limited -10 < value < 10. d can be a list or tuple. This appears to be the beginning of a rabbit hole.

Describe alternatives you've considered

As an alternative, I would be happy enough to be able to show all parameters just after the class docstring, similarly to what is shown above when executing A?.

@Davide-sd Davide-sd added the type:proposal a feature suggestion label Oct 20, 2024
@electric-coder
Copy link

electric-coder commented Oct 20, 2024

What syntax is this?

A?

The first one: let autoattribute be aware of param.

That should be a Sphinx extension because creating a dependency in Sphinx on 3rd party library syntax isn't a good design choice. You should post this FR at the param repo.

@Davide-sd see holoviz/param#197

@AA-Turner AA-Turner closed this as not planned Won't fix, can't repro, duplicate, stale Oct 20, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type:proposal a feature suggestion
Projects
None yet
Development

No branches or pull requests

3 participants