NiklasRosenstein / pydoc-markdown

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

Render type annotations for object attributes #229

Closed calebho closed 2 years ago

calebho commented 2 years ago

Is your feature request related to a problem? Please describe.

Would be nice if documented object attributes also included a type annotation (if it exists)

Describe the solution you'd like

Given the following object

class Foo:
  #: a bar attribute
  bar: str

It should produce documentation like (not exact, just to get the idea across)

# Foo
## bar: `str`
a bar attribute

Describe alternatives you've considered

Repeating the type annotation in the doc comment. However this is suboptimal because I need to repeat myself and the comment + type annotation could get out of sync

Additional context

NiklasRosenstein commented 2 years ago

Hi @calebho ,

Thanks for the suggestion; I've added a render_typehint_in_data_header option to the Markdown renderer. I've enabled it by default in the Hugo example, and this is what it looks like:

image