Enable mypy type checking for torchvision.io - #9608
Conversation
Three of the ignore_errors exemptions in mypy.ini are no longer needed:
* torchvision.io.video_reader does not exist. There is no video_reader
module anywhere in the tree, so the exemption matches nothing.
* torchvision.io.video is a 23 line re-export shim that already carries
its own type: ignore[import-not-found] for the internal fb import.
* torchvision.io.image is clean apart from `import
torchvision_extra_decoders`, an optional dependency imported inside a
try block.
That last one is handled by adding torchvision_extra_decoders to the
existing ignore_missing_imports block, which is where the other optional
dependencies already live (PIL, numpy, scipy, av, h5py, gdown and so on),
rather than by adding an inline ignore.
No source files change. mypy still reports no issues across 185 files,
and the three modules are now actually checked instead of skipped.
Verified with the pinned CI version, mypy 1.13.0:
mypy --config-file mypy.ini
Success: no issues found in 185 source files
Removing the torchvision_extra_decoders entry alone reproduces the single
error it suppresses, so the entry is doing real work.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/9608
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
Hi @atikulmunna! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Three of the
ignore_errorsexemptions inmypy.iniare no longer earning their place, so this removes them and lets those modules be type checked. No source files change.torchvision.io.video_readerdoes not exist. There is novideo_readermodule anywhere in the tree, so the exemption matches nothing.torchvision.io.videois a 23 line re-export shim that already carries its own# type: ignore[import-not-found]for the internal fb import.torchvision.io.imageis clean apart fromimport torchvision_extra_decoders, an optional dependency imported inside atryblock.For that last one I added
torchvision_extra_decodersto the existingignore_missing_importsblock, where the other optional dependencies already live (PIL,numpy,scipy,av,h5py,gdownand so on), rather than adding an inline ignore to the source.Verification
Run with the version CI pins,
mypy==1.13.0:Unchanged
mainreports the same, so this keeps the check green while removing three exemptions.I confirmed the new entry is not decorative: dropping only the
torchvision_extra_decoderssection reproduces the single error it suppresses.One note on reproducing locally: mypy's incremental cache can hide that difference, so the control needs
--no-incrementalor a cleared.mypy_cache.Not included
The five remaining exemptions need real source changes and are better off as separate PRs. Measured individually against this commit, they are
transforms.functional.*4 errors,transforms.transforms.*7,ops.*23,transforms._functional_pil32, andmodels.*97. Happy to work through them if that is wanted.