Skip to content

Docstrings of parent methods #78

Closed

Description

@jan-matthis

How would I render docstrings of methods inherited from a parent class?

To try this out, here is a minimal example for which I'd have expected parent_method to show up as part of the test.Child docstring:

# test.py

class Parent:
    def parent_method(self, arg):
        """Parent method
        
        Args:
            arg: Arg
        """

class Child(Parent):
    def child_method(self, arg):
        """Child method
        
        Args:
            arg: Arg
        """
# index.md

::: test.Child
    selection:
      members:
        - child_method
        - parent_method

Activity

  1. pawamoy commented on Apr 9, 2020

    @pawamoy
    Member

    Indeed inherited members are not picked up by pytkdocs right now. I wonder if we should pick them up by default and let the users filter the members, or if we should add another option like Sphinx's inherited-members.

  2. jan-matthis commented on Apr 9, 2020

    @jan-matthis
    Author

    Thanks for the quick answer! Maybe it's good to have the extra flexibility of inherited-members to be able to apply separate filters on them (and show all without leading _ by default)? Either way, this would be a highly useful feature.

  3. pawamoy commented on Apr 9, 2020

    @pawamoy
    Member

    So you're suggesting to simply copy the members configuration option as inherited_members, and make it accept the same possible values (true, false, or a list of names)?

  4. jan-matthis commented on Apr 9, 2020

    @jan-matthis
    Author

    Yes, that's what I was thinking of

  5. pawamoy commented on Apr 9, 2020

    @pawamoy
    Member

    OK, it should be fairly easy to implement then. I'll open the corresponding feature request on pytkdocs.

  6. added
    feature
    on Apr 9, 2020
  7. pawamoy commented on Jun 8, 2020

    @pawamoy
    Member

    Alright. I just released pytkdocs version 0.5.0. mkdocstrings does not yet accept it. I'll increase the version range soon. You will then be able to add a inherited_members: true to the selection options. The option only accepts a boolean, not a list of members, nor a list of filters: I wanted to do a simple pass first. If you all really need the ability to select or filter inherited members differently than direct members, we will open a new feature request.

  8. ofek commented on Jun 8, 2020

    @ofek
    Contributor

    Hmm, mkdocstrings/pytkdocs#43

    edit: fixed

  9. pawamoy commented on Jun 9, 2020

    @pawamoy
    Member

    Closing! Open new issues if other problems arise 🙂

  10. cgarciae commented on Jul 8, 2020

    @cgarciae

    Hey, I am not able to inherit documentation for __init__, is there are restriction regarding this method?

  11. pawamoy commented on Jul 10, 2020

    @pawamoy
    Member

    Oh, yeah, it happens here: https://github.com/pawamoy/pytkdocs/blob/master/src/pytkdocs/loader.py#L587-L600. I think we could safely remove this since we can now chose to inherit or not.

  12. cgarciae commented on Jul 27, 2020

    @cgarciae

    @pawamoy being able to inherit the docs of the __init__ method would save me a lot of work. Is this a planed feature?

  13. cgarciae commented on Jul 27, 2020

    @cgarciae

    I think for the same reason, I also cant get the documentation for inherited class methods right now.

  14. pawamoy commented on Jul 27, 2020

    @pawamoy
    Member

    Yes, I'd consider the current behavior a bug. Could you open a new issue? Just a sentence and a link to your previous comment will do :) It's hard to keep track of things in comments.

    Also, a PR is welcome, I'm too busy these days :/

    Thanks!

  15. samsja commented on Mar 17, 2023

    @samsja

    I cannot make this work 😕 can someone explain how the index.md should look like for it to work ? Thanks in advance 🙌

  16. famura commented on Apr 17, 2023

    @famura

    Hi @pawamoy, I am rather new to mkdocs / mkdocstrings and a bit confused on this issue. Like the thread opener, I want my doc strings to be repeated for the child classes / mehtods if not specified otherwise. I can do this with sphinx, but would much rather use mkdoc.

    So far, I tried this configuration in my mkdocs.yml

    ...
    plugins:
      ...
      - mkdocstrings:
          handlers:
            python:
              ...
              options:
                inherited_members: true
                ...
    

    However, this had no effect. I've just read that this feature is not implemented (yet). Does that mean I have to look for a workaround now?

    Best whishes and many thanks!

  17. pawamoy commented on Apr 17, 2023

    @pawamoy
    Member

    Hey @famura, yes indeed, this is not yet implemented. If you find a workaround let us know 🙂

  18. famura commented on Apr 17, 2023

    @famura

    OK, thank you for your super quick response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions