Skip to content

FIX: correct v2 format argument type hints - #1206

Merged
FirefoxMetzger merged 2 commits into
imageio:masterfrom
psgundla:fix/v2-format-type-hints-1194
Sep 29, 2026
Merged

FirefoxMetzger merged 2 commits into
imageio:masterfrom
psgundla:fix/v2-format-type-hints-1194

Conversation

@psgundla

@psgundla psgundla commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #1194.

The V2 API accepts a format name/extension string or None, but its stubs currently annotate format as Format. This makes valid calls such as imageio.v2.get_writer(path, format="PNG") fail static type checking.

  • Use Union[str, None] for format throughout the V2 reader/writer signatures and overloads, consistent with decypher_format_arg.
  • Preserve reader/writer return types, byte-output overloads, and aliases.
  • No runtime behavior changes.

Validation

  • python -m pytest tests/test_v2.py -m 'not needs_internet' -q: 9 passed, with the official test-image fixtures cached locally.
  • black --check --target-version py312 imageio/v2.pyi: passed with Black 26.3.0.
  • git diff --check: passed.
  • Standalone mypy 2.3.1 client checks covering all V2 reader/writer functions and aliases with string, explicit None, and omitted formats, plus the four byte-output overloads: 36 errors before this change; zero after.
  • Negative client checks still reject Format, int, and arbitrary object values for format.

The mypy checks were run locally, not added as a new project-wide typing harness. Imported-module diagnostics were suppressed using follow_imports = silent, follow_imports_for_stubs = True, and ignore_missing_imports = True to isolate the client-facing regression from unrelated existing stub diagnostics.

@FirefoxMetzger

Copy link
Copy Markdown
Contributor

The CI failure are unrelated. Otherwise this looks good :)

I forgot to merge the current master into this PR before running the CI. Triggered a re-run; assuming it comes back green I'll merge.

@psgundla

Copy link
Copy Markdown
Contributor Author

Thanks for checking and rerunning CI! Everything looks green now.

@psgundla psgundla closed this Sep 28, 2026
@FirefoxMetzger

Copy link
Copy Markdown
Contributor

hehe, could you reopen the PR @psgundla ? I had to go into my meetings before CI was all green so I didn't press merge yet and you closed the PR instead 😅

I'm happy to just create a new PR with your changes and tag you, but I think the contribution/history will be cleaner if we merge this one that you authored.

@psgundla psgundla reopened this Sep 29, 2026
@psgundla

Copy link
Copy Markdown
Contributor Author

Oops, my mistake 😅 I’ve reopened it. Thanks for catching that and for taking the time to review!

@FirefoxMetzger
FirefoxMetzger merged commit 8e80054 into imageio:master Sep 29, 2026
33 checks passed
@FirefoxMetzger

Copy link
Copy Markdown
Contributor

Merged! Thanks again @psgundla

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect type hints for "format" argument in v2.pyi

2 participants