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

How can we propagate inherited functionality documentation without __pdoc__ ? #295

Closed
djberenberg opened this issue Aug 19, 2021 · 2 comments

Comments

@djberenberg
Copy link

djberenberg commented Aug 19, 2021

Problem Description

Greetings! I am a new user of pdoc, it's so easy to use!

I have a system with multiple inheritance, I would like all inherited functionality to be documented in the child class. If __pdoc__ still existed, I think this would be possible, but in light of its currently suspended support, is there a solution for this?

code example

Suppose we have this class hierarchy:

class A:
    def a(self) -> str:
        """a doc"""
        return 'a'
class B:
     def b(self) -> str:
         """b doc"""
          return 'b'

class C(A, B):
    """C doc
    """
    pass

I would like the documentation of C to render as if I had something like:

class C(A, B):
    """C doc 
    """
    def a(self) -> str:
       """a doc"""
        return super().a()
    
    def b(self) -> str:
        """b doc"""
        return super().b()

Is this possible right now?

Proposal

None. This is more of a question.

Alternatives

I guess one alternative is to use the system as is, with inherited members. But I would like to view everything on the same page without changing the structure of my library.

Additional context

None

@mhils
Copy link
Member

mhils commented Aug 20, 2021

Hi there! Generally speaking pdoc really intends to document your API as it is, but there may be a few exceptions where what you are looking for makes sense (you mentioned mixins on Slack).
This is nothing that pdoc supports out of the box, but you should be able to get there easily by modifying the default template. We have a module_contents block which you can override with your own:

{% block module_contents %}
{% for m in module.flattened_own_members if is_public(m) | trim %}
<section id="{{ m.qualname or m.name }}">
{{ member(m) }}
{% if m.type == "class" %}
{% for m in m.own_members if m.type != "class" and is_public(m) | trim %}
<div id="{{ m.qualname }}" class="classattr">
{{ member(m) }}
</div>
{% endfor %}
{% set inherited_members = inherited(m) | trim %}
{% if inherited_members %}
<div class="inherited">
<h5>Inherited Members</h5>
<dl>
{{ inherited_members }}
</dl>
</div>
{% endif %}
{% endif %}
</section>
{% endfor %}
{% endblock %}

If you change the access from m.own_members to m.members in line 794 and remove the inheritance part starting in line 799, you should be good to go. 😃 https://pdoc.dev/docs/pdoc/doc.html has all the documentation for the objects you are working with here.

@djberenberg
Copy link
Author

Thanks @mhils for the prompt response! Very elegant solution. Closing this issue.

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

No branches or pull requests

2 participants