Sphinx: Sphix indicates that a sync function is async

Created on 26 Apr 2020  路  5Comments  路  Source: sphinx-doc/sphinx

This one is maybe my fault, but I'm not sure what I should be doing.

Describe the bug
I'm generating async methods from sync methods this way:

    @functools.wraps(wrapped)
    def wrapper(*args, **kwargs):
        awaitable = wrapped(*args, **kwargs)
        return sync_await(awaitable=awaitable)

Because I use functools.wraps and after https://github.com/sphinx-doc/sphinx/pull/7222, Sphinx sees that my sync function wraps an async function and unwraps it in iscoroutinefunction. the wrapped function is async, so the function is async.

When documenting, both the original and wrapped functions are seen as async.

To Reproduce
Steps to reproduce the behavior:

$ git clone https://github.com/peopledoc/procrastinate
$ cd procrastinate
$ pip install tox
$ tox -e docs
$ # open docs/_build/html/reference.html#procrastinate.tasks.Task.defer, it's noted as async

Expected behavior
Not really sure. For a staticmethod, for example, it makes sense to consider it async even if it's the wrapped method that is async.

Your project
https://github.com/peopledoc/procrastinate
https://github.com/peopledoc/procrastinate/blob/9dd6c296ddf59bb524e20cd6bd09703ff00a8f66/procrastinate/utils.py

Screenshots
Capture d鈥檈虂cran 2020-04-26 a虁 14 58 22

Environment info

  • OS: All
  • Python version: 3.7.7
  • Sphinx version: Sphinx==3.0.2
  • Sphinx extensions:
extensions = [
    "sphinx.ext.napoleon",
    "sphinx.ext.autodoc",
    "sphinx_autodoc_typehints",
    "sphinxcontrib.programoutput",
    "changelog",
]

Additional context
I'm not sure is this is because I shouldn't be using wraps if I expect the wrapper and the wrapped function to be seen as distinct, or if I'm doing something unexpected. I know I'm probably doing something weird in the first place with automatic synchronous functions generation, so if you think this is out of scope, I understand.

If there's a workaround, though, I'm interested.

autodoc bug

Most helpful comment

Don't mind. I'm encouraged by donation itself. Either way is okay!

Also, GitHub doesn鈥檛 let you chose a custom amount?

Sorry, I don't know. It seems no way to do that.

All 5 comments

Wow that was fast. I expected more discussions. Very nice to see that my strange use-case is now in the sphinx test suite.

@tk0miya you rock, and having you take care of my recent issues in Sphinx has been a blast. Thank you! The only tangible way of thanking you I can think of besides saying thanks is sponsoring you, so I'll be doing that for the next months to come :) (via patreon. Not a lot, I know but :) )

As I commented at #7571, python's inspect.iscoroutinefuncion() considers it as non-coroutine-function. I believe it makes common sense to python developers. So it's not a hard decision for me.

And thank you for offering sponsorship. I'll continue to work with your support. If you don't mind the platform, GitHub sponsor is better for me. Because GH increases your patronage via thier fund during this year. Anyway, thank you for your support.

Oh, I found your patronage on patreon now. Please forget my comment above. Thanks a lot!

Ah. Patreon is easier for me because I already give to other creators. It makes a single expense in the month. I try to limit the number of platforms I use because I鈥檓 afraid I won鈥檛 be able to track all donations properly otherwise :) But duly noted: if I find other developers to sponsor and especially if I want to sponsor people who are only on GitHub, I鈥檒l make the switch for you too.

Also, GitHub doesn鈥檛 let you chose a custom amount?

Don't mind. I'm encouraged by donation itself. Either way is okay!

Also, GitHub doesn鈥檛 let you chose a custom amount?

Sorry, I don't know. It seems no way to do that.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jfbu picture jfbu  路  3Comments

eine picture eine  路  3Comments

shimizukawa picture shimizukawa  路  3Comments

scolby33 picture scolby33  路  3Comments

shimizukawa picture shimizukawa  路  3Comments