NiklasRosenstein / pydoc-markdown

Create Python API documentation in Markdown format.
http://niklasrosenstein.github.io/pydoc-markdown/
Other
460 stars 105 forks source link

Support for attribute docstrings #53

Closed trojkat closed 4 years ago

trojkat commented 6 years ago

According to PEP 257 you can add string literals immediately after a simple assignment at the top level of a module, class, or init.

class Foo(object):
  velocity = 1
  """Foo's initial velocity - class variable"""

Current output (which also breaks the indentation of the next item):

<h3 id="Foo.velocity">velocity</h3>

int(x=0) -> integer
int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments
are given.  If x is a number, return x.__int__().  For floating point
numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string,
bytes, or bytearray instance representing an integer literal in the
given base.  The literal can be preceded by '+' or '-' and be surrounded
by whitespace.  The base defaults to 10.  Valid bases are 0 and 2-36.
Base 0 means to interpret the base from the string as an integer literal.
>>> int('0b100', base=0)
4

Expected output:

<h3 id="Foo.velocity">velocity</h3>

```python
velocity = 1
```

Foo's initial velocity - class variable
NiklasRosenstein commented 6 years ago

We have to switch to using a parser instead of actually importing the Python module(s), as the docstring for the variable is lost in that process. I would also like to support # comments before the variable as docstring.

I intend to use lib2to3 for that purpose.

NiklasRosenstein commented 5 years ago

Just a heads up, I'm currently working on this in the develop branch.

sbischoff-ai commented 5 years ago

A useful little feature for the meantime would be a flag or something to ignore non-callable members. This would at least allow to use pydocmd as it is now on a codebase with public class attributes without having to correct the markdown by hand after generation. Because right now I'm kinda tempted to pre-underscore my class attributes and wrap them in classmethods, just to make automated documentation work, and I guess that's not a good thing. I'd be willing to work on a PR for that, if that's fine with you. :)

NiklasRosenstein commented 5 years ago

Hey @sbischoff-ai , I must have missed your comment. If you are still willing to create a PR, please do! I do not plan to make many more changes to v2 but important fixes and want to focus the little time I can invest into this project on v3.

NiklasRosenstein commented 4 years ago

This is working in Pydoc-Markdown 3. 🙂