Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Properties do not inherit superclass docstrings #90

Closed
jayqi opened this issue Feb 6, 2021 · 2 comments
Closed

[BUG] Properties do not inherit superclass docstrings #90

jayqi opened this issue Feb 6, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@jayqi
Copy link

jayqi commented Feb 6, 2021

Describe the bug

Properties do not properly inherit docstrings from parent class if they are not set.

To Reproduce

I observed this when rendering documentation using mkdocstrings.

  • Sub class with missing property docstrings: link
  • Super class with property docstrings defined: link

From looking at the pytokdocs source code, I think the problem is because the get_property_documentation method is using inspect.getdoc on prop.fget instead of prop directly (link).

Based on my experimentation below, both the property itself and fget work for the superclass but only the property and not fget work the subclass.

import inspect

class SuperClass:
    @property
    def read_only(self):
        """SuperClass.read_only docs"""
        return 0

    @property
    def mutable(self):
        """SuperClass.mutable getter docs"""
        return 0

    @mutable.setter
    def mutable(self, value):
        pass

class SubClass(SuperClass):
    @property
    def read_only(self):
        return 1

    @property
    def mutable(self):
        return 1

    @mutable.setter
    def mutable(self, value):
        pass

inspect.getdoc(SuperClass.read_only)
#> 'SuperClass.read_only docs'

inspect.getdoc(SuperClass.read_only.fget)
#> 'SuperClass.read_only docs'

inspect.getdoc(SuperClass.mutable)
#> 'SuperClass.mutable getter docs'

inspect.getdoc(SuperClass.mutable.fget)
#> 'SuperClass.mutable getter docs'


inspect.getdoc(SubClass.read_only)
#> 'SuperClass.read_only docs'

inspect.getdoc(SubClass.read_only.fget)

inspect.getdoc(SubClass.mutable)
#> 'SuperClass.mutable getter docs'

inspect.getdoc(SubClass.mutable.fget)

Created on 2021-02-05 by the reprexpy package

Expected behavior

Sub class properties should inherit docstrings from their parents when not set.

System (please complete the following information):

  • pytkdocs==0.10.1
  • mkdocstrings==0.14.0
  • Python: 3.8.6
  • OS: macOS
@pawamoy
Copy link
Member

pawamoy commented Feb 7, 2021

Hi @jayqi! Thanks a lot for the detailed report and the examples. I'll see if we can use getdoc on the property itself rather than its fget method.

@pawamoy pawamoy added the bug Something isn't working label Feb 7, 2021
@pawamoy
Copy link
Member

pawamoy commented Feb 7, 2021

Pushed a fix, will release it soon, closing!

@pawamoy pawamoy closed this as completed Feb 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants