Look into using mypy's daemon #1577
Copy link
Copy link
Closed
Labels
area-editor-*User-facing catch-allUser-facing catch-allarea-lintingfeature-requestRequest for new features or functionalityRequest for new features or functionality
Description
Reacted by Don Jayamanne, Eric Hiller, ly-cultureiq, David Wehr, Matan Gover, Ivan Levkivskyi, yxliang, theomessin, SHxKM, Pavel Struhar and 118 more
Reacted by Don Jayamanne
Metadata
Metadata
Assignees
Labels
area-editor-*User-facing catch-allUser-facing catch-allarea-lintingfeature-requestRequest for new features or functionalityRequest for new features or functionality
Activity
erichiller commentedon Jul 26, 2018
Looks like as of June 2018 work has begun for Windows daemon support.
python/mypy#5019
emmatyping commentedon Nov 27, 2018
FYI, mypy master now has a working implementation of the mypy daemon for Windows if you want to play with it.
erichiller commentedon Dec 30, 2018
How would we be able to use
dmypywithin vscode? Do you mean just for testing via the command line? Or is there a proper way to integrate this with vscode currently? If not are there plans to use the daemon or give the option?emmatyping commentedon Dec 30, 2018
Eric Hiller (@erichiller) Until there is more official support, as a work around you can use something like the following:
Though this is rather hackish. (It won't kill the daemon when VS Code closes, which likely is not the behavior you want). Also this is rather abusing the whole "set an executable and args" settings system...
Do note you must change the argument for following imports to either skip or error for now.
brettcannon commentedon Jan 3, 2019
Eric Hiller (@erichiller) we would like to add support, but we don't have any ETA on when this will get prioritized high enough for us to get around to it.
ethanhs thanks for the work-around!
DonJayamanne commentedon May 9, 2019
Ivan Levkivskyi (@ilevkivskyi)
Thanks for connecting with us at PyCon, looking forward to landing this in the extension.
Lets get the ball rolling.
A few questions (there'll be a few more, but lets start with a few simple ones):
dmypy start.ilevkivskyi commentedon May 9, 2019
Don Jayamanne (@DonJayamanne)
I think the simplest way is to set current working directory to the repo root when calling
dmypy startcommand.No it will not die. Process created by
dmypy start(client) exits immediately, but it leaves the daemon (server) "detached". The daemon however will shut down after a timeout if it receives no requests (configurable, default is 24 hours). Also callingdmypy killunconditionally kills the server.Mypy only supports Python 3.5+, it can type check older versions (including 2.7), but you need to have Python 3 installed to run it. If you want to type check a repo in Python 2 mode and then in Python 3 mode, I think the best way is to start two daemons each one configured with
--python-version=x.y(you will also need to pass--status-file XXXto each daemon when starting the server, and when communicating with them usingdmypyclient to distinguish them).Currently this is not possible.
dmypy checkanddmypy recheckare blocking calls, i.e. they don't exit before the server responds with the checking, and then they print checking results to stdout and exit. From user point of viewdmypy checkbehaves essentially the same asmypy. You can of course issuer anotherdmypy check(i.e. create another client process) before previous exits, but I am not sure this is going to end well currently. We discussed the possibility to adddmypy cancelto gracefully abort last type checking request, and it may be not so easy to implement. But potentially we can do this if it is important.It is not how mypy normally works (not only the daemon), see #5587. I actually believe we should figure out that issue first before continuing here.
13 remaining items
rben01 commentedon Feb 19, 2021
This doesn't work for me. Here's the Python extension's output:
Looks like it's changed how it does
mypylinting so that you can't just pass it arbitrary command line arguments.adam-grant-hendry commentedon Mar 4, 2021
At the risk of asking a dumb question, if I can get
mypylinting using the right json settings per ethanhs ... why do I need to run the daemon? What added benefit does the daemon give me that I'm not already getting by linting?rben01 commentedon Mar 5, 2021
I believe that (non daemon) mypy must start up and re-read any cached data before beginning to work on the files you pass it, which takes some time. In contrast the daemon remains in memory and has no startup cost for runs after the first, so it should return results much faster.
reporter123 commentedon Aug 15, 2021
Robert (@rben01) Your not even getting that far.
This means mypy is not being found at all. Like because it isn't installed in the python virtual environment you are running in. Ran into the same thing myself under different circumstances.
matangover commentedon Oct 27, 2021
Ian Stokes-Rees (@ijstokes) FWIW I implemented most of what you asked for in my mypy extension a few months ago. It now runs the mypy daemon directly for each workspace folder. I also added the
runUsingActiveInterpreteroption which I think you were asking for.lithammer commentedon Oct 28, 2021
I opened a ticket to upgrade dmypy to a language server a while back. I guess that could be relevant for this as well:
dmypyto a language server (LSP) python/mypy#10463KholdStare commentedon Jan 13, 2023
Any updates?
JamesHutchison commentedon Apr 11, 2023
This dev container template uses the daemon:
https://github.com/JamesHutchison/python-dev-container-template
I agree that the daemon makes more sense in general, however the daemon has also been somewhat "semi-experimental" as it runs a different code path so I can understand being hesitant to use it by default.
If your repo is very large and has a very large number of errors, both mypy and dmypy are atrociously slow. This is because the daemon uses errors as a signal to reprocess a file, even if it wasn't touched.
karthiknadig commentedon Jun 14, 2023
We now have a preview version of
mypyextension that usesdmypyfor linting. Please give it a try:https://marketplace.visualstudio.com/items?itemName=ms-python.mypy-type-checker
tusharsadhwani commentedon Jun 14, 2023
Karthik Nadig (@karthiknadig) just a heads up, using dmypy by default for vscode may cause bugs like this to surface, causing users problems: python/mypy#12249
karthiknadig commentedon Jun 14, 2023
Tushar Sadhwani (@tusharsadhwani) The extension allows you to configure it to run using
mypyas well usingmypy-type-checker.pathsetting. You can point it to themypyexecutable to use that. You can use variable resolution support to configure themypy-type-checker.pathlike "${workspaceFolder}.venv\bin\mypy", or if you havemypyglobally or from an activated environment, you could even just say"mypy-type-checker.path": ["mypy"]karthiknadig commentedon Oct 19, 2023
Closing this against https://marketplace.visualstudio.com/items?itemName=ms-python.mypy-type-checker
FYI, that extension allows you to switch between
dmypyormypyusing themypy-type-checker.preferDaemonsetting. Default isdmypy.