Skip to content

Fix return type of CalibrationDataReader.get_next#27784

Open
liyuqian wants to merge 1 commit intomicrosoft:mainfrom
liyuqian:fix-calibration-data-reader-get-next-return-type
Open

Fix return type of CalibrationDataReader.get_next#27784
liyuqian wants to merge 1 commit intomicrosoft:mainfrom
liyuqian:fix-calibration-data-reader-get-next-return-type

Conversation

@liyuqian
Copy link

Describe your changes

CalibrationDataReader.get_next was annotated with -> dict, but the method contract allows returning None to signal end-of-data — as evidenced by __next__ checking if result is None: raise StopIteration.

This PR fixes the return type annotation to Optional[dict] and adds the necessary from typing import Optional import.

Change summary

  • onnxruntime/python/tools/quantization/calibrate.py: Change get_next(self) -> dict to get_next(self) -> Optional[dict]

Motivation and Context

The incorrect type annotation causes type-checking tools (e.g. mypy, pyright) to flag any code that checks if result is None as unreachable, and misleads users implementing the abstract method into thinking None is not a valid return value.

Test Plan

This is a type annotation fix only — no behavioral changes. Existing tests cover the runtime behavior.

Related Issues

N/A

The method can return None to signal end-of-data (causing __next__ to
raise StopIteration), but was incorrectly annotated as -> dict.
Change the return type to Optional[dict] to match the actual contract.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@liyuqian liyuqian changed the title Fix return type of CalibrationDataReader.get_next to Optional[dict] Fix return type of CalibrationDataReader.get_next Mar 20, 2026
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.

1 participant