Skip to content

Conversation

@gpauloski
Copy link
Collaborator

@gpauloski gpauloski commented Apr 22, 2024

Description

Adds the proxystore.mypy_plugin mypy plugin that helps mypy determine the types of attributes and methods accessed on a Proxy[T].

The plugin can be enabled within the mypy config. For example, in pyproject.toml:

[tool.mypy]
plugins = ["proxystore.mypy_plugin"]

I used a lot of resources to figure this out that may be helpful to later attempts at similar plugins:

Fixes

Type of Change

  • Breaking Change (fix or enhancement which changes existing semantics of the public interface)
  • Enhancement (new features or improvements to existing functionality)
  • Bug (fixes for a bug or issue)
  • Internal (refactoring, style changes, testing, optimizations)
  • Documentation update (changes to documentation or examples)
  • Package (dependencies, versions, package metadata)
  • Development (CI workflows, pre-commit, linters, templates)
  • Security (security related changes)

Testing

Testing is a bit different here. Because mypy is a static analysis tool, I've added tests which check types using assert_type for "good" and type: 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_plugin module 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.

  • Tags added to PR (e.g., breaking, bug, enhancement, internal, documentation, package, development, security).
  • Code changes pass pre-commit (e.g., mypy, ruff, etc.).
  • Tests have been added to show the fix is effective or that the new feature works.
  • New and existing unit tests pass locally with the changes.
  • Docs have been updated and reviewed if relevant.

@gpauloski gpauloski added the enhancement New features or improvements to existing functionality label Apr 22, 2024
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.
@gpauloski gpauloski merged commit 885e0a6 into main Apr 22, 2024
@gpauloski gpauloski deleted the mypy-plugin branch April 22, 2024 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New features or improvements to existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create a mypy plugin for ProxyStore

2 participants