python-lsp / pylsp-mypy

Mypy plugin for the Python LSP Server.
MIT License
118 stars 35 forks source link

Feature request: Support type information #63

Open jjlee opened 1 year ago

jjlee commented 1 year ago

I'd like to be able to hover cursor/mouse over a variable and see mypy type information.

Could pylsp-mypy support that?

As far as I know, mypy provides two ways to access this information at present, neither of which are perfect for this purpose:

  1. dmypy supports this as of 0.981 https://mypy.readthedocs.io/en/latest/mypy_daemon.html#statically-inspect-expressions -- but I think your README.md says that dmypy only currently gives you any info on saving to disk? Better than nothing.
  2. reveal_type/reveal_locals. I guess in principle pylsp could sneak in a reveal_locals() to whatever function point is on before sending the file to mypy (obviously this has its problems!)

At present, the only other way I know of to get this information in emacs is using reveal_locals() (or reveal_type) and having flycheck show the note-level info about that that contains the types. However, this flycheck issue makes that awkward for now (and quite non-obvious that you can even see types that way!). Also of course it's annoying to have to add reveal_locals() whenever you want to see types.

Richardk2n commented 1 year ago

Might be possible, and I am interested in implementing it.

The daemon is (as of the time I last checked) not able to shadow unsaved files. Still, using that would be the preferred way to go.

I will have a look at it.