dropbox / mypy-PyCharm-plugin

A simple plugin that allows running mypy from PyCharm and navigate between errors
Apache License 2.0
313 stars 14 forks source link

Right-click on function to apply annotation suggestions #53

Open chadrik opened 4 years ago

chadrik commented 4 years ago

Would be great to make use of dmypy suggest to add annotations to existing code.

ilevkivskyi commented 4 years ago

Actually you can already do this in some sense. There is a hidden (or rather just not advertised as official) hot key Ctrl+Shift+Y that will launch a script at ./mypy/mypy-suggest (hardcoded) and pass it current file name and current line number and then reloads the doc. You can write a short script that essentially pipes dmypy suggest to pyannontate -w that will apply the suggestion in-place.

But yeah, making it on right click and more automated would be great.

chadrik commented 4 years ago

Actually you can already do this in some sense. There is a hidden (or rather just not advertised as official) hot key Ctrl+Shift+Y that will launch a script at ./mypy/mypy-suggest (hardcoded) and pass it current file name and current line number and then reloads the doc.

I see. I tried this out and it failed with this error:

/bin/bash ./mypy/mypy-suggest: no such file or directory

I started pycharm from a shell where dmypy suggest -h works, and the mypy console in pycharm works correctly as well. Perhaps what's hardwired is not dmypy suggest?

On a related note, I've been playing around with dmypy suggest and it doesn't seem to take the current scope into consideration when generating annotations.

I get something like this:

dmypy suggest mymodule.myfunc
() -> mymodule:Dict[str, mymodule.Dict[str, module.MyClass]]

When I expect something like this:

dmypy suggest mymodule.myfunc
() -> Dict[str, Dict[str, MyClass]]

The annotations produced by dmypy suggest won't work without being fixed up. Is this by design, or a bug, or user error?

ilevkivskyi commented 4 years ago

Perhaps what's hardwired is not dmypy suggest?

Of course it isn't, please read carefully the sentence you quoted.

Is this by design, or a bug, or user error?

I think this is by design. We have been using this extensively internally for long time, and it worked well for pyannotate.