Fix return type of CalibrationDataReader.get_next#27784
Open
liyuqian wants to merge 1 commit intomicrosoft:mainfrom
Open
Fix return type of CalibrationDataReader.get_next#27784liyuqian wants to merge 1 commit intomicrosoft:mainfrom
liyuqian wants to merge 1 commit intomicrosoft:mainfrom
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your changes
CalibrationDataReader.get_nextwas annotated with-> dict, but the method contract allows returningNoneto signal end-of-data — as evidenced by__next__checkingif result is None: raise StopIteration.This PR fixes the return type annotation to
Optional[dict]and adds the necessaryfrom typing import Optionalimport.Change summary
onnxruntime/python/tools/quantization/calibrate.py: Changeget_next(self) -> dicttoget_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 Noneas unreachable, and misleads users implementing the abstract method into thinkingNoneis 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