Properties listed under "Attributes" are not formatted correctly
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 355
- Forks
- 181
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 3
Description
I recently found myself trying to document a mix of normal attributes and properties on a class using Numpydoc for the first time, and it did not work well. I have a class more-or-less like this:
class ExampleClass:
"""
This is an example of how attributes and attributes that are properties get
formatted by numpydoc.
Attributes
----------
normal_attribute : str
This is a normal attribute, fully specified in class docstring.
property_attribute
"""
def __init__(self):
self.normal_attribute = 'hello'
@property
def property_attribute(self):
"""
This attribute is actually a property (i.e. it's actually a function
call under the hood). The description is pulled from the docstring of
the method that implements it.
Returns
-------
int
"""
return len(self.normal_attribute)
According to the docs:
Attributes that are properties and have their own docstrings can be simply listed by name
Which is what I tried to do here. However, the output…
- Formats the attribute name for the property different from normal attributes (as a code sample rather than as bold text).
- Does not include the type. (I’ve specified it as the return value of the property implementation; not sure if I should have done something else.)
- Cuts off the description after the first period that is followed by whitespace. I think this is supposed to be the first sentence, but that’s not a great assumption (see this example, which has a period that doesn’t end the sentence).
Here’s a screenshot of the output:
Or with sphinx_rtd_theme, where the differences are more obvious:
I would have expected properties to be treated the same as normal attributes in the final output. Have I got something configured wrong, or am I misunderstanding the intended syntax? Otherwise this seems a bit like a bug.
I’ve added a complete example you can just install and build the docs from at https://github.com/Mr0grog/example-numpy-attribute-property-issues if that helps.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the complete example linked in the issue and reproduce its generated documentation using the documented Attributes syntax. Compare property attributes with normal attributes, including formatting, type display, and sentence truncation; done means properties render consistently with normal attributes and preserve the intended description.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100