12

Trying to setup mypy with my PyCharm Professional 2017.2. But it doesn't work. I also would like to setup mypy check on one particular file vs entire project, can some please share the way they have configured mypy in their PyCharm.

bad_coder
  • 11,289
  • 20
  • 44
  • 72
yadayada
  • 327
  • 1
  • 3
  • 14
  • 2
    Mypy is a program you can run from the command line. So, I would try looking up information on how to run arbitrary command line applications from within Pycharm. You can also just use Pycharm's built-in checking and inference tools, which understands PEP 484 types/can perform typechecking, just like mypy. – Michael0x2a Oct 31 '17 at 03:09
  • Hi @Michael0x2a thanks, yes the command line option is there. But I'm currently using Pycharm so was setting up mypy with Pycharm – yadayada Nov 01 '17 at 00:07
  • Yes -- if I remember correctly, you can do things like set up a run configuration within Pycharm that calls the command line. Then, you can just click a button -- Pycharm will then run mypy (via the command line) for you. It's not perfect integration, but then again, Pycharm comes built-in with its own native support for PEP 484 types (basically, Pycharm's built-in functionality is a viable replacement for mypy), so nobody is probably prioritizing getting that integration working more smoothly. – Michael0x2a Nov 01 '17 at 03:31

4 Answers4

10

You can use the mypy-pycharm plugin to have real-time and on-demand scanning with mypy from within PyCharm/IDEA.

This plugin has also a feature to scan just the current selected file (the green play button on the left side bar):

enter image description here

Roberto Leinardi
  • 10,641
  • 6
  • 65
  • 69
7

You can add an external tool in the "run/Debug configurations" of pycharm.

Pycharm will then run mypy first, you will see a new tab in the run window, if it is successful then it can run your python script (or in my example below it will run my django unit tests).

There is also a trick to use $PyInterpretorDirectory$/mypy so that pycharm will pickup mypy from the right location.

enter image description here

Lingster
  • 977
  • 10
  • 21
3

Could be an import issue. Check mypy configurations for pycharm (assuming mypy plugin already installed) Argument --follow-imports normal makes the difference mypy configurations in pycharm

drt
  • 735
  • 6
  • 16
2

One other option is to use File Watcher. This will check for any mypy errors and notes on save.

enter image description here

TreeNode
  • 472
  • 1
  • 7
  • 10