DEV Community

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

Collapse
 
waylonwalker profile image
Waylon Walker

Thanks for sharing your journey back to pycharm with us. I started using pycharm when I first learned python , but it took too many resources to do that and pro e for my main job. I ended up running sublime text for quite awhile, a short period in vscode, before landing full time in neovim.

Any reason you're going to pycharm? I could see the appeal of it just mostly works out of the box..

I've recently started really leaning in on the vim features that most vim emulators are missing, jumplist, taglist, quickfix.

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.

Collapse
 
thraizz profile image
Aron Schüler

While nvim-lsp is really useful, it is as limited as the LSP it is using. I found the proprietary PyCharm LSP incredibly useful when working on large-scale django applications. The autocompletion is incredible there!
I still use nvim (nightly) for the frontend part of my fullstack role, but for now I cannot live without e.g. Car.objects.filter(driver__address__city="Detroit").values("some__other__attribute") where both driver address and some_other_attribute will be offered as auto completion. I didn't get this "deep insight" to work with nvim nor with VS Code.