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

Inherit docstring from super class when missing in subclass #6287

Open
kkom opened this issue Aug 22, 2024 · 1 comment
Open

Inherit docstring from super class when missing in subclass #6287

kkom opened this issue Aug 22, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@kkom
Copy link

kkom commented Aug 22, 2024

Hey! I've got a request similar to #877 but related to class docstrings instead.

See the code below:

class A:
    """
    My docstring.
    """

class B(A): ...

a = A()
b = B()

Here is what Pylance shows on hover for each class:

Screenshot 2024-08-22 at 10 21 13 Screenshot 2024-08-22 at 10 20 57

It would be great if B inherited A's docstring in the absence of its own. Especially as this is the behaviour of inspect.getdoc:

In [1]: import inspect

In [2]: inspect.getdoc(A)
Out[2]: 'My docstring.'

In [3]: inspect.getdoc(B)
Out[3]: 'My docstring.'
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Aug 22, 2024
@debonte
Copy link
Contributor

debonte commented Aug 22, 2024

I thought we already supported this, but the code path I was thinking of is specifically for inheriting docstrings for overridden methods (which is working). See getFunctionDocStringInherited.. I guess that was the result of #877 which you referenced above.

class A:
    """
    My docstring.
    """
    
    def method(self):
        """
        My method docstring.
        """
        pass

class B(A):
    def method(self):
        pass

a = A()
b = B()

a.method()
b.method()

image

@debonte debonte added bug Something isn't working and removed needs repro Issue has not been reproduced yet labels Aug 22, 2024
@kkom kkom changed the title Inherit docstring from super class when missing Inherit docstring from super class when missing in subclass Sep 26, 2024
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

3 participants