[Python-Dev] Best way to specify docstrings for member objects (original) (raw)
MRAB python at mrabarnett.plus.com
Tue Mar 19 16:52:02 EDT 2019
- Previous message (by thread): [Python-Dev] Best way to specify docstrings for member objects
- Next message (by thread): [Python-Dev] Best way to specify docstrings for member objects
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 2019-03-19 18:55, Raymond Hettinger wrote:
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. This keeps all the relevant information in one place (much like we already do with property() objects). This way already works, we just need a few lines in pydoc to check to see if a dict if present. This way also looks pretty and doesn't feel awkward. I've included worked out examples below. What do you all think about the proposal? [snip]
Thinking ahead, could there ever be anything else that you might want also to attach to member objects?
I suppose that if that's ever the case, the value could itself be expanded to be a dict, something like this:
slots = {'mu' : {'doc': 'Arithmetic mean.'}, 'sigma': {'doc': 'Standard deviation.'}}
But that could be left to the future...
- Previous message (by thread): [Python-Dev] Best way to specify docstrings for member objects
- Next message (by thread): [Python-Dev] Best way to specify docstrings for member objects
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]