Open martinkozle opened 1 year ago
Hi, thanks for your suggestion. This is maybe possible to implement using a feature that mypy added recently - dmypy inspect. However I don't think I'll have time to do that. Contributions are welcome.
It seems not possible at the moment to use dmypy inspect
for inlay hints. It could be used for hovers, however.
We looked at this with a friend a while ago and came to the same conclusion. Inlay hints are done through the language server, which in this case is Pylance. And we can't really change what Pylance shows in the inlay hints.
But I think the hover type hints would be even better and more helpful anyways. The rust-analyzer extension for Rust has them very well implemented where if you select any piece of code it gives you the type of the selected piece of code.
Example image:
An example in Python would be if you partially or fully select
len(lst)
in the hover it would give you the type int
.
I think this would be quite useful of a feature for Python, but I don't know if dmypy
is able to inspect and give type hints for selected bits of code.
Yes, that seems possible.
Inlay hints are done through the language server, which in this case is Pylance
Does vscode support multiple language servers at once? Alternatively, does Pylance support plugins?
Is it possible on a technical level for this extension to overwrite the inlay type hints from Pylance (Pyright) with ones from MyPy? If so, would you consider this to be a feature worth implementing?
The reason why I would like this feature personally is because I use MyPy for typing but VS Code's Python language server, Pylance, shows hover and inlay hints from Pyright, which is a lot of the time different from MyPy. This makes it confusing when trying to keep the code MyPy valid. An example where this is an issue is:
The inlay hint shows the type revealed from Pylance, which when typing with MyPy in mind gives the wrong impression of the type.
I was considering posting this feature request directly to the Pylance repository, but since Pylance's whole point is that it is based on it's own type checker I thought that this extension implementing it would be a better fit.