NiklasRosenstein / pydoc-markdown

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

Markdown class properties? #181

Closed stephend017 closed 3 years ago

stephend017 commented 3 years ago

Problem

Currently the markdown renderer doesn't render class properties, which in most classes are meant to be public.

Example of problem


class MyClass:

    def __init__(self):
        self._my_read_only_var = 1

    # this is rendered by the markdown processor because it is a class method
    def get_my_read_only_var(self) -> int:
        """ 
        returns the my_read_only_var variable but is accessed like a method

       Ex:
           myclass_instance.my_read_only_var()
        """
        return self._my_read_only_var

    # this is not rendered by the markdown processor because it is a class property
    @property
    def my_read_only_var(self) -> int:
        """ 
        also returns my_read_only_var but is accessed like a normal property

        Ex:
            myclass_instance.my_read_only_var
        """
        return self._my_read_only_var

However having documentation of properties is important because they are meant to be public.

Solution

Add class properties to the markdown renderer, to behave the same way class methods do, but require their generation to include the @property decorator. They should follow the same config options set for Methods.

NiklasRosenstein commented 3 years ago

Thanks for reporting @stephend017. There might be something going wrong in the logic that filters which members are rendered.

stephend017 commented 3 years ago

I agree. I believe that's because the property decorator returns its own type.

NiklasRosenstein commented 3 years ago

Hey @stephend017 ,

I did not track fixing this specifically, but I think it's working as intended now. 😄

https://github.com/NiklasRosenstein/pydoc-markdown/blob/3352261d8661ac09ff046deb67291c11a0502189/pydoc-markdown/src/test/testcases/renderers/markdown/class_02_with_property.txt