Add the proxystore.mypy mypy plugin for resolving Proxy[T] types#545
Merged
Add the proxystore.mypy mypy plugin for resolving Proxy[T] types#545
proxystore.mypy mypy plugin for resolving Proxy[T] types#545Conversation
Adds some new packages to the mypy pre-commit hook and fixes many mypy errors that are already present or will be present once the proxystore mypy plugin is added.
Having the proxystore.mypy plugin causes issues when loading the plugin via a path (as opposed to module) as we do in pyproject.toml. Mypy loads in the "mypy" module within "proxystore/" which overwrites the actual mypy module which proxystore.mypy imports from. While we could specify "proxystore.mypy" within the pyproject.toml and this problem would go away (I also think it looks cleaner), this causes problems with the mypy pre-commit hook. Pre-commit does not install the local package so "proxystore.mypy" is not a valid import for mypy when run within the pre-commit virtual environment. Renaming proxystore.mypy to proxystore.mypy_plugin prevents the name clash and will have to do.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds the
proxystore.mypy_pluginmypy plugin that helps mypy determine the types of attributes and methods accessed on aProxy[T].The plugin can be enabled within the mypy config. For example, in
pyproject.toml:I used a lot of resources to figure this out that may be helpful to later attempts at similar plugins:
Fixes
Type of Change
Testing
Testing is a bit different here. Because mypy is a static analysis tool, I've added tests which check types using
assert_typefor "good" andtype: ignore[...]for "bad".This means that the tests when run with pytest are essentially no-ops and will always pass even if the mypy plugin is altered. By running mypy/pre-commit should catch the errors. Additionally, the
proxystore.mypy_pluginmodule is excluded from coverage. This could be fixed in the future but would require the test suite to measure coverage over multiple tests.Pull Request Checklist
Please confirm the PR meets the following requirements.
pre-commit(e.g., mypy, ruff, etc.).