Replace mypy with ty for static type checking#585
Conversation
ty (from Astral, makers of ruff/uv) replaces mypy as the project's static type checker. Benchmark on this codebase (631 source files): | Metric | mypy | ty | Speedup | |-------------|----------|-------|---------| | Cold cache | 184.6s | 0.79s | ~234x | | Warm cache | 13.9s | 0.83s | ~17x | Changes: - Add ty to lint deps, remove mypy + mypy-extensions (keep mypy-protobuf for protoc stub generation) - Migrate mypy.ini config to [tool.ty.*] sections in pyproject.toml - Update Makefile type_check target: `uv run ty check` - Downgrade 12 rule categories to "warn" for initial migration; a follow-up PR will fix the 226 warnings and promote them back to errors - Update docs (CLAUDE.md, README.md, CHANGELOG.md, .claude/formatting.md) - Update .gitignore/.dockerignore cache directory references - Replace "mypy" mentions in source comments with generic "type checker" - Delete mypy.ini Co-Authored-By: shubhamvij <25601958+shubhamvij@users.noreply.github.com>
- Pin ty~=0.0.29 for reproducible builds - Add comment clarifying mypy-protobuf is for stub generation only - Exclude notebooks (*.ipynb) from type checking - Add comment about torch lacking inline types/stubs - Promote all ty rules back to default error severity (remove warn downgrades — fixes come in a follow-up PR) - Add [[tool.ty.overrides]] to suppress errors in generated *_pb2.py files that cannot be fixed Co-Authored-By: shubhamvij <25601958+shubhamvij@users.noreply.github.com>
| [tool.ty.src] | ||
| exclude = ["*_pb2.py", "*_pb2.pyi", "**/*.ipynb"] | ||
|
|
||
| [tool.ty.analysis] |
There was a problem hiding this comment.
Migrated from mypy.ini - removed any that could be fixed - thank you robots!
svij-sc
left a comment
There was a problem hiding this comment.
I updated the downstream PR where I addressed the ty fixes and to it added some new fixes identified by @kmontemayor2-sc below.
Ref: #586
kmontemayor2-sc
left a comment
There was a problem hiding this comment.
I do feel pretty strongly about not type ignoring torch, WDYT about including #597 as part of the follow up here?
Otherwise this LGTM, thanks for the work :)
Co-authored-by: shubhamvij <25601958+shubhamvij@users.noreply.github.com> Co-authored-by: Kyle Montemayor <kmontemayor2@snapchat.com> Co-authored-by: kmontemayor <kyle.e.montemayor@gmail.com>
I pulled in the changes - thanks @kmontemayor2-sc |
kmontemayor2-sc
left a comment
There was a problem hiding this comment.
Awesome work Shubham! Really appreciate it :)
| @@ -402,10 +420,12 @@ def __batch_copy_blobs( | |||
| dst_prefix: str, | |||
| src_blobs: list[storage.Blob], | |||
| ): | |||
| dst_blob_names: list[str] = [ | |||
| src_blob.name.replace(src_prefix, dst_prefix, 1) | |||
| for src_blob in src_blobs | |||
| ] | |||
| dst_blob_names: list[str] = [] | |||
| for src_blob in src_blobs: | |||
| assert src_blob.name is not None, ( | |||
| "Blob from list_blobs must have a name" | |||
| ) | |||
| dst_blob_names.append(src_blob.name.replace(src_prefix, dst_prefix, 1)) | |||
There was a problem hiding this comment.
hmm is it easier to do blobs = [b for b in self.__list_file_blobs_at_gcs_path(gcs_path=gcs_path) if b.name is not None on line 213?
| if isinstance(_uri, GcsUri): | ||
| exists = self.__gcs_utils.does_gcs_file_exist(gcs_path=_uri) | ||
| elif type(_uri) == LocalUri: | ||
| exists = does_path_exist(cast(LocalUri, _uri)) | ||
| elif type(_uri) == HttpUri: | ||
| exists = HttpUtils.does_http_path_resolve(http_path=cast(HttpUri, _uri)) | ||
| elif isinstance(_uri, LocalUri): | ||
| exists = does_path_exist(_uri) | ||
| elif isinstance(_uri, HttpUri): | ||
| exists = HttpUtils.does_http_path_resolve(http_path=_uri) |
There was a problem hiding this comment.
isn't this a real logic change?
I suppose this is better since it catches sub classes?
| # on values imported from those modules. | ||
| # https://docs.astral.sh/ty/reference/configuration/#replace-imports-with-any | ||
| replace-imports-with-any = [ | ||
| "apache_beam.**", |
There was a problem hiding this comment.
I don't think apache_beam was ignored before? I assume ty is unhappy with this? Can we test if we remove this?
ty (from Astral, makers of ruff/uv) replaces mypy as the project's static type checker.
The ty fixes are introduced here: #586
Benchmarked on the code base (631 source files):
Changes:
uv run ty checkScope of work done
Where is the documentation for this feature?: N/A
Did you add automated tests or write a test plan?
Updated Changelog.md? NO
Ready for code review?: YES