Problem: When using NewType or the Python 3.12 type alias, docstrings don't work. Sphinx extract the description from the comment after the alias definition, but for generating parameters for widgets we would like to use __doc__. Currently we have, e.g.,
BackgroundRun = NewType('BackgroundRun', int)
"""Background run: the run with only the solvent which the sample is placed in."""
I now tried the following:
def alias(name: str, tp: type, doc: str) -> type:
ntp = NewType(name, tp)
ntp.__doc__ = doc
return ntp
BackgroundRun = alias(
'BackgroundRun',
int,
"Background run: the run with only the solvent which the sample is placed in.",
)
Unless some Sphinx cache tricked be, this seems to work with both Sphinx autodoc and defined a usable __doc__.
Problem: When using
NewType
or the Python 3.12type
alias, docstrings don't work. Sphinx extract the description from the comment after the alias definition, but for generating parameters for widgets we would like to use__doc__
. Currently we have, e.g.,I now tried the following:
Unless some Sphinx cache tricked be, this seems to work with both Sphinx autodoc and defined a usable
__doc__
.