DEV Community

Discussion on: How To Get Black Working in PyCharm in 2021

Collapse
 
zev profile image
Zev Averbach

Yeah, it’s the included batteries, in particular the refactoring and go-to-definition ones. It’s “home” and then vim is my minimal cabin in the woods; I’ve just been in the cabin for a longer stretch than usual. 🙂

Collapse
 
waylonwalker profile image
Waylon Walker

Do you prefer to keep your vim config minimal or would you be willing to bring refactoring and go-to-definition to vim?

Thread Thread
 
zev profile image
Zev Averbach

totally open. HOWEVER, let me up the ante and say that I also want the one-keystroke (two?) pip install and import functionality. 😃

Thread Thread
 
waylonwalker profile image
Waylon Walker

Can you give me an example? Does pycharm do this. I'm thinking of several things you could be referring to.

Thread Thread
 
zev profile image
Zev Averbach

Yeah, if I import from a package that isn’t installed in a project’s virtualenv, then press alt-space over that import and it’s squiggly underline, I get a context menu whose first option is to install the package.

Similarly, if I invoke a function (or anything) that doesn’t exist in the current module’s namespace, alt-space over that thing brings up a context menu the first option of which (i think) is to import it.

Thread Thread
 
waylonwalker profile image
Waylon Walker • Edited

I've had auto import working with the native lsp, but it's spotty and I don't understand enough to debug it yet. Does pycharm handle installing packages with a diferent package name than you import? I think I could easily make a keybinding that does a pip install of the word under the cursor, but I don't have a clue how you would figure out that bs4 is beautifulsoup4 or pil is pillow. Are these features that you use ofen? I leverage cookiecutter heavily so I end up with everything in requirements.txt.

Anyways, I was just curious. I can't choose what editor makes you most comfortable or productive, nor would I want anyone using an editor that was not by choice. I really like nvim and the benefits it gives me, thats why I use it.

Thread Thread
 
zev profile image
Zev Averbach

No I think differently named packages probably can’t be auto installed. what I like about pycharm is that it tells me right away about things I’m calling which haven’t been imported, and then not having to navigate anywhere to put the import statement in. So in that context I use it very frequently, and I also very frequently waste time when developing in vim because of forgotten imports.

I always end up fiddling quite a bit with whichever editor I’m using, so I don’t think either editor wins on that, but PyCharm is less flexible, which limits my fiddling a little bit.

Thread Thread
 
waylonwalker profile image
Waylon Walker • Edited

What version of vim are you on? Some options I've had success with to get the red underline is ALE or the native lsp in nvim. I am really digging the native lsp in nvim 0.5.0, but as its still only in nightly it there is not quite as much content around it, so setting it up has taken more time than I'd like to admit that I spent on it. ALE is something that I installed long ago and didn't realize all the great things it does until shortly before uninstalling it. ALE feels quite battle tested and seemed like it did a lot out of the box. There was a setting or two that felt annoying that I changed, but it was pretty minimal compared to the current state of native lsp or coc.vim.

Here is what some errors look like on my setup.

I'm trying to swich from pyright to pyls as it will allow me to use mypy for type checking. Currently pyright complains about a bunch of pandas stuff that mypy does not. pyright seems to work with the least config though if you are already on nvim 0.5.0

Thread Thread
 
zev profile image
Zev Averbach

Mmm, depends on whether I'm doing work or personal stuff, but I think I switched back to Vim 8-point-something from nvim 0.4.something a couple months ago. I used Ale for quite a while for linting + fixing, it worked fine. Also, the vim emulation in Jetbrains lacks some pretty important things, like it won't autocomplete a word if it happens to exist as a variable but you're trying to complete it in a string. There are a few other things like that.