You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How would we be able to use dmypy within 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?
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.
Reacted by Fabrice Normandin, Robert, Dustin Martin and Dan Strokirk
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.
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):
How do we start multiple daemons for different repositories? The docs don't cover that.
Assume user opens two instances of VS Code, both instances of VSC will now run dmypy start.
My assumption is, this will result in two instances of the daemon.
Will shutting down the parent process kill the daemon automatically or is it a detached sub process?
I.e. if we were to kill vscode (non-graceful shutdown), will this result in the daemon evetually killing itself, or will it stay alive and never die?
Silyy question:
Assume we have two instances of vscode, one using Python 2.7 another using python 3.7. When Python2.7 sends requests to the daemon, will it send the messages to the daemon that it started.
I guess the answer is obviously yes, just don't want to make assumptions here.
Cancellation,
Assume we send a command to lint a large file, and immediately after that we send the same file (but with some changes). Will mypy cancel the previous request or will it simply queue the request. I.e. wait for previous request to complete.
Multiple requests
Assume we send a command to lint a large file
While we're waiting for that request to be processed we send another request to the same daemon to process a large file, will the daemon block on the previous request or somehow process this in parallel?
How do we start multiple daemons for different repositories?
I think the simplest way is to set current working directory to the repo root when calling dmypy start command.
[...] I.e. if we were to kill vscode (non-graceful shutdown), will this result in the daemon evetually killing itself, or will it stay alive and never die?
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 calling dmypy kill unconditionally kills the server.
Assume we have two instances of vscode, one using Python 2.7 another using python 3.7. When Python2.7 sends requests to the daemon, will it send the messages to the daemon that it started.
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 XXX to each daemon when starting the server, and when communicating with them using dmypy client to distinguish them).
Assume we send a command to lint a large file, and immediately after that we send the same file (but with some changes). Will mypy cancel the previous request or will it simply queue the request. I.e. wait for previous request to complete
Currently this is not possible. dmypy check and dmypy recheck are 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 view dmypy check behaves essentially the same as mypy. You can of course issuer another dmypy 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 add dmypy cancel to 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.
Assume we send a command to lint a large file.
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.
This doesn't work for me. Here's the Python extension's output:
> ~/Library/Caches/pypoetry/virtualenvs/env-name-py3.8/bin/python ~/.vscode/extensions/ms-python.python-2021.2.576481509/pythonFiles/pyvsc-run-isolated.py -c "import dmypy"
Linter 'mypy' is not installed. Please install it or select another linter".
Error: Module 'dmypy' not installed.
Looks like it's changed how it does mypy linting so that you can't just pass it arbitrary command line arguments.
At the risk of asking a dumb question, if I can get mypy linting 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?
At the risk of asking a dumb question, if I can get mypy linting 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?
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.
Linter 'mypy' is not installed. Please install it or select another linter".
Error: Module 'dmypy' not installed.
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.
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 runUsingActiveInterpreter option which I think you were asking for.
Reacted by Tushar Sadhwani, Emma Smith and Charles Swartz
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.
Tushar Sadhwani (@tusharsadhwani) The extension allows you to configure it to run using mypy as well using mypy-type-checker.path setting. You can point it to the mypy executable to use that. You can use variable resolution support to configure the mypy-type-checker.path like "${workspaceFolder}.venv\bin\mypy", or if you have mypy globally or from an activated environment, you could even just say "mypy-type-checker.path": ["mypy"]
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.