Improve stubs (typing information)
Closes #702 (closed)
Here we considerably improve our stubs (however, there is still room for improvement :-( ) :
- in our generate_stubs.cmake we should not copy main
__init__.pyi, but the__init__.pyifrom the "_tango" subfolder. This file actually contains stubs for the extension. With this file IDE now know all function signatures and can show proper auto-completion at runtime:
Before:
After:
We still can have main __init__.pyi - but I cannot understand, what it brings. THE QUESTION: do we also need to copy all others ".pyi" files?
-
The problem with
@staticmethodwas due to we wrap the method with the@green(and@_trace_client, but this does not matter for docs) decorator, which is based onfunctools.wraps. Thepybind11-stubsuses for method analysis inspect.getfullargspec, which, as we know, does not work in this case. So it could not properly analyse function signature and marked as static. To solve it we must preserve signature in our decorators. -
Then, since we, actually, know the real method signatures and our extension (at least now) does not accept kwargs - we can make methods signatures real (at least some of them) - this also helps with stubs
-
and the last - since we anyway play with signatures in
@greendecorator and we know that it adds three kwargs (and they must be kwargs only) - we can add them automatically to the signature. And they will be show in stubs. The main problem here is that*args, **kwargssignature cannot be updated, and, due to@greenis public - we do it only if optional kwargupdate_signature_and_docstringset to True -
and finnaly - we can also automatize docsring generation in case of
@greendecorator. I propose, that in docstring we just add__GREEN_KWARGS__,__GREEN_KWARGS_DESCRIPTION__and__GREEN_RAISES__placeholders and the@greenautomatically adds here preper description. -
I revised all bindings, and added everywhere py::arg() = now generated stubs does not look like
method(arg0, arg1), but with real names. As additional benefit = we now can call all methods with kwargs -
I tried to minimize erorrs durin pybind11-atubgen (however, fully remove them is super-complicated due to cirlucar dependencies of classes)
So, now our stubs for DeviceProxy and AttribueProxy are almost good.

