Open MarcSkovMadsen opened 2 years ago
Thanks a lot @MarcSkovMadsen for opening this issue. As a VS Code user too I think we share the same feeling! This is something I'd be happy to work when I find the time.
According to https://github.com/microsoft/pyright/issues/2855 we would probably have to add the constructors manually all over the place or align the api of Param with the api of dataclasses.
There's also more details over in the Pyright issue in regards to using .pyi
files if you want the type information to live outside of the code itself.
Just for reference I tried changing to the Jedi language server. But the result was the same
we would probably have to add the constructors manually
Sounds to me like we can construct this automatically by introspection?
I have the code to create stub .pyi
files for all Parameterized classes in Panel.
https://github.com/holoviz/panel/pull/3132 (param_stubgen.py file)
I just need the functionality to add the relevant imports to the top of the .pyi
files. And then test and probably spend lots of time on fixing surprices :-)
Note the challenge for VS code is that is works via static type analysis as opposed to Jupyter that works via dynamic analysis. VS Code use pyright. Pyright does not instantiate classes to inspect them. It uses static analysis only.
Currently the HoloViz system is difficult to use in VS Code with as you don't get any context help. For example for Panel the only thing you get is
I.e. you don't get any docstring. You don't get any information on the arguments the
__init__
accepts.@philippjfr points out in https://github.com/holoviz/panel/issues/3085 that ..., we explicitly enabled signatures on Parameterized class constructors which should be the accepted way to declare the accepted kwargs.
@brettcannon points out in https://github.com/holoviz/panel/issues/3085 that For attrs at least, they implemented https://github.com/microsoft/pyright/blob/main/specs/dataclass_transforms.md which I believe is in the process of becoming a proposed PEP. It's documented at https://www.attrs.org/en/stable/extending.html?highlight=pyright#pyright .
Suggestion
dataclass_transforms
is a solution for Param. And if it is implement.The alternative would be to reach out to pyright and ask why they don't use the
signatures
of pep362 and/ or if they could.