[Python-Dev] Best way to specify docstrings for member objects
storchaka at gmail.com
Wed Mar 20 03:41:34 EDT 2019
19.03.19 20:55, Raymond Hettinger пише:
> I'm working on ways to make improve help() by giving docstrings to member objects.
> One way to do it is to wait until after the class definition and then make individual, direct assignments to __doc__ attributes.This way widely the separates docstrings from their initial __slots__ definition. Working downstream from the class definition feels awkward and doesn't look pretty.
> There's another way I would like to propose¹. The __slots__ definition already works with any iterable including a dictionary (the dict values are ignored), so we could use the values for the docstrings.
I think it would be nice to separate docstrings from the bytecode. This
would be allow to have several translated sets of docstrings and load an
appropriate set depending on user preferences. This would help in
It is possible with docstrings of modules, classes, functions, methods
and properties (created by using the decorator), because the compiler
knows what string literal is a docstring. But this is impossible with
namedtuple fields and any of the above ideas for slots.
It would be nice to allow to specify docstrings for slots as for methods
and properties. Something like in the following pseudocode:
It would be also nice to annotate slots and add default values (used
when the slot value was not set).
mu: float = 0.0
sigma: float = 1.0
More information about the Python-Dev