Skip to content

Enable mypy type checking for torchvision.io - #9608

Open
atikulmunna wants to merge 1 commit into
pytorch:mainfrom
atikulmunna:typing/enable-mypy-for-torchvision-io
Open

Enable mypy type checking for torchvision.io#9608
atikulmunna wants to merge 1 commit into
pytorch:mainfrom
atikulmunna:typing/enable-mypy-for-torchvision-io

Conversation

@atikulmunna

Copy link
Copy Markdown

Three of the ignore_errors exemptions in mypy.ini are no longer earning their place, so this removes them and lets those modules be type checked. No source files change.

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

For that last one I added torchvision_extra_decoders to the existing ignore_missing_imports block, where the other optional dependencies already live (PIL, numpy, scipy, av, h5py, gdown and so on), rather than adding an inline ignore to the source.

Verification

Run with the version CI pins, mypy==1.13.0:

$ mypy --config-file mypy.ini
Success: no issues found in 185 source files

Unchanged main reports 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_decoders section reproduces the single error it suppresses.

torchvision/io/image.py:435: error: Cannot find implementation or library stub
for module named "torchvision_extra_decoders"  [import-not-found]

One note on reproducing locally: mypy's incremental cache can hide that difference, so the control needs --no-incremental or 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_pil 32, and models.* 97. Happy to work through them if that is wanted.

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.
@pytorch-bot

pytorch-bot Bot commented Aug 15, 2026

Copy link
Copy Markdown

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

@meta-cla

meta-cla Bot commented Aug 15, 2026

Copy link
Copy Markdown

Hi @atikulmunna!

Thank you for your pull request and welcome to our community.

Action Required

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

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla meta-cla Bot added the cla signed label Aug 15, 2026
@meta-cla

meta-cla Bot commented Aug 15, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant