pyinfra-dev / pyinfra

pyinfra turns Python code into shell commands and runs them on your servers. Execute ad-hoc commands and write declarative operations. Target SSH servers, local machine and Docker containers. Fast and scales from one server to thousands.
https://pyinfra.com
MIT License
3.91k stars 382 forks source link

Docstrings not displayed for functions using the operator decorator #1055

Closed Denperidge closed 8 months ago

Denperidge commented 10 months ago

Describe the bug

On VSCode, you cannot view the docstrings for operations (e.g. server.user() and the like). This seems to be because of the @operation wrapper

To Reproduce

A VSCode screenshot of server.user being hovered over. There are no docstrings nor keywords shown. This is the first descriptor of the 2 A VSCode screenshot of server.user being hovered over, but with the second descriptor selected. There are no docstrings nor keywords shown

Alternatively, you can add from pyinfra.api import operation and test this out on a local function. As seen below, the docstrings get jambled up as soon as the @operation decorator is used. A VSCode screenshot of a simple function called meow.  The docstring is displayed, and no parameters are shown to be available, as is the case A VSCode screenshot of a simple function called meow, but with the @ operation decorator.  The docstring is no longer displayed, and there are now unclear parameters are shown to be available, even though this is not the case

Expected behavior

The docstrings displaying! This is the output when copying the server.user function, but don't add the decorator! A VSCode screenshot of a function descriptor. server.user got copied without the @operation hovered over. Docstrings are displayed as expected, and the keywords are visible

Possible solution?

In terms of Python3, I was only able to find this bug thread in the sphinx repository: https://github.com/sphinx-doc/sphinx/issues/3783 . It describes multiple potential solutions (e.g. functools.wrap, or custom wrapping thing)

Meta

Fizzadar commented 9 months ago

Hi @Denperidge, would you mind trying this with the v3.b0 release? I’ve rewritten the type annotations for operations and have tested it working in VSCode.

Denperidge commented 8 months ago

Sorry for the late reply @Fizzadar , but here to confirm that it is fixed in v3.b0! Thank you very much!