Skip to content

Add dmypy watch command #18985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

NiclasvanEyk
Copy link

@NiclasvanEyk NiclasvanEyk commented Apr 27, 2025

Fixes #13033

This PR adds the dmypy watch command. It is basically the same as repeatedly running dmypy check FILES and then sleeping for X (defaults to 1) seconds. Here is a short video of it in action:

Screen.Recording.2025-04-27.at.20.50.36.mov

I wrote a new non-data-driven test that takes about 10s to complete on my local machine. I don't think an implementation in daemon.test would have been as readable, so I resorted to a classic unittest.TestCase.

Alternatives

This polling approach is quite simple and maybe a bit naive, but it works without introducing additional dependencies. For large projects, I assume that listening to filesystem events and only re-checking changed files (with some debouncing logic) is a better fit.

Since Python does not offer a builtin, cross-platform solution for listening to filesystem events, one would need to use third-party dependencies like watchdog to solve this, e.g. as an optional dependency. If it is installed, one could use a the more efficient approach, otherwise fall back to the simple polling approach. However, this is outside of the scope of this PR.

This comment has been minimized.

Running recheck did not detect new files created while watching
@NiclasvanEyk NiclasvanEyk force-pushed the dmypy-watch-command branch 2 times, most recently from 70408bc to 3468dd9 Compare April 28, 2025 19:58

This comment has been minimized.

Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(🎁) dmypy should have a watch mode (⌚)
1 participant