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

Type aliases and descriptions for parameters #63

Open
SimonHeybrock opened this issue Aug 5, 2024 · 0 comments
Open

Type aliases and descriptions for parameters #63

SimonHeybrock opened this issue Aug 5, 2024 · 0 comments

Comments

@SimonHeybrock
Copy link
Member

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__.

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

No branches or pull requests

1 participant