Could this be a use case for typing.Annotated?
In [6]: from dataclasses import dataclass
In [7]: from typing import Annotated
In [8]: class A:
...: """Docstring for class A."""
...: x: Annotated[int, "Docstring for x"]
...: y: Annotated[bool, "Docstring for y"] = True
In [9]: A.__annotations__
Out[9]:
{'x': typing.Annotated[int, 'Docstring for x'],
'y': typing.Annotated[bool, 'Docstring for y']}
The syntax is a bit arduous; I'd be in favor of thinking through ways to
make it easier to write. But the basic functionality already exists;
there's no reason to duplicate it with another language feature.
Rick.
---
Ricky.
"I've never met a Kentucky man who wasn't either thinking about going home
or actually going home." - Happy Chandler
On Thu, Nov 18, 2021 at 5:50 AM <[email protected]> wrote:
> Stephen J. Turnbull wrote:
> > @standard_class_docstring_parser
> > class A:
> > """
> > Class docstring.
> > x: Docstring for x
> > y: Docstring for y
> > """
> > x: int
> > y: bool = True
>
> Oh, this is actually a nice idea. You could have a
> decorator that parses reST and then according
> to some conventions extracts the attribute
> docstrings. I think I will try to write something like
> that.
>
> Thomas
> _______________________________________________
> Python-ideas mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/[email protected]/message/F2QJ3Q3HFX5VR7MG37FXET5JJ2XVNKSF/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/GXPHAXUXQ3UGWK6YZFSNVSWYGL22INDM/
Code of Conduct: http://python.org/psf/codeofconduct/