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

autodoc: Inherited async methods not detected #19

Closed
twisteroidambassador opened this issue Nov 9, 2018 · 5 comments · Fixed by #141
Closed

autodoc: Inherited async methods not detected #19

twisteroidambassador opened this issue Nov 9, 2018 · 5 comments · Fixed by #141

Comments

@twisteroidambassador
Copy link

When using autodoc to document a class that inherits an async method from its base class, the inherited method is not detected as async.

Basically, with code like this:

class SomeBaseClass:
    """The base class."""
    async def base_async_method(self):
        """This is an async method in the base class."""
        pass

class SomeDerivedClass(SomeBaseClass):
    """The derived class."""
    async def derived_async_method(self):
        """This is an async method in the derived class."""
        pass

and autodoc directives like this:

.. automodule:: some_async_module
   :members:
   :inherited-members:

The output documentation is like this:

class some_async_module.SomeBaseClass

The base class.

await base_async_method()

    This is an async method in the base class.

class some_async_module.SomeDerivedClass

The derived class.

base_async_method()

    This is an async method in the base class.

await derived_async_method()

    This is an async method in the derived class.
@twisteroidambassador
Copy link
Author

inherit_async.zip

Here's a test case replicating the issue.

Tested on:
Sphinx==1.8.1
sphinxcontrib-trio==1.0.1

@DevilXD
Copy link
Contributor

DevilXD commented Mar 13, 2020

Just ran into this issue myself, it looks like this is not fixed. Is this project still getting maintained? The issue appears to be over 16 months old =/

@njsmith
Copy link
Member

njsmith commented Mar 13, 2020

@DevilXD the project is still maintained and in use, but it's on a volunteer, best effort kind of basis, so issues only get fixed if someone is motivated to do it. If this is causing problems for you, then maybe you're the right volunteer to figure out what's going on and fix it :-)

@DevilXD
Copy link
Contributor

DevilXD commented Mar 14, 2020

@njsmith Unfortunately I have 0 clue what is going on, or how to debug this even - my breakpoints doesn't seem to work. This is breaking my documentation and I could at least try fixing it, but I don't think I have enough knowledge of sphinx internals to be able to do so =/

Unless you're willing to explain or point me in the right direction with this, I might just look for an alternative (if there is one), and if not, do what the discord.py project did - add a note to each function stating when it's a coroutine, and when it isn't.

@DevilXD
Copy link
Contributor

DevilXD commented Mar 14, 2020

After some tinkering around by modifying the installed library directly and adding print statements (cos doing proper debugging is too hard apparently, from the previous comment), it looks like the issue is in the 358 line:

obj = self.parent.__dict__.get(self.object_name)

Doing this doesn't resolve the MRO entires in any way, and just does a lookup directly on the class, so every inherited method just returns None at that point, and since that has no __wrapped__ attribute on it, trying to sniff options does nothing later on as well. Not sure how to solve this considering that the comment right above that line states that getattr cannot be used (although it would properly resolve the MRO entires), but I'll think about it and make a PR if possible.

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

Successfully merging a pull request may close this issue.

3 participants