holoviz / param

Param: Make your Python code clearer and more reliable by declaring Parameters
https://param.holoviz.org
BSD 3-Clause "New" or "Revised" License
421 stars 72 forks source link

Support Intellicode in VS Code. Probably using dataclass_transforms #587

Open MarcSkovMadsen opened 2 years ago

MarcSkovMadsen commented 2 years ago

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

image

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

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.

maximlt commented 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.

MarcSkovMadsen commented 2 years ago

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.

image

brettcannon commented 2 years ago

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.

MarcSkovMadsen commented 2 years ago

Just for reference I tried changing to the Jedi language server. But the result was the same

image

image

jbednar commented 2 years ago

we would probably have to add the constructors manually

Sounds to me like we can construct this automatically by introspection?

MarcSkovMadsen commented 2 years ago

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.