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 5 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.

@NiclasvanEyk NiclasvanEyk force-pushed the dmypy-watch-command branch 3 times, most recently from 3468dd9 to e8d3d38 Compare April 28, 2025 20:03

This comment has been minimized.

1 similar comment

This comment has been minimized.

@NiclasvanEyk NiclasvanEyk force-pushed the dmypy-watch-command branch from 54f4874 to 2788f02 Compare May 3, 2025 13:06

This comment has been minimized.

everything else seems to break pytest
Copy link
Contributor

github-actions bot commented May 4, 2025

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