Fix MetricRunner.run() return-type annotation and document side effect#92
Open
lonexreb wants to merge 1 commit intoNVlabs:mainfrom
Open
Fix MetricRunner.run() return-type annotation and document side effect#92lonexreb wants to merge 1 commit intoNVlabs:mainfrom
lonexreb wants to merge 1 commit intoNVlabs:mainfrom
Conversation
`MetricRunner.run` declares `-> dict[str, Any]` but the body has no
`return` statement -- Python returns `None` implicitly while the
annotation lies, which trips up type checkers and confuses callers
who assume they should read a result from the return value.
The body's actual contract is:
output_batch.update({"metric/" + k: v for k, v in per_sample_metrics.items()})
i.e. metrics are merged into `output_batch` in-place. This is the
documented behavior in the class docstring ("...added to the output
batch") and matches every existing call site.
This commit:
- Changes the return annotation from `dict[str, Any]` to `None` to
reflect the actual behavior.
- Expands the one-line docstring to spell out the in-place mutation
contract and explicitly note that callers should read results from
`output_batch` after the call.
No runtime behavior change.
Signed-off-by: lonexreb <[email protected]>
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.
Problem
MetricRunner.runinsrc/alpamayo_r1/metrics/metric_runner.pydeclares-> dict[str, Any]but the body has noreturnstatement:Python returns
Noneimplicitly while the annotation lies. This trips up type checkers (mypy,pyright) and is misleading to callers who reasonably assume they should read a result from the return value.The actual contract — documented in the class docstring ("…added to the output batch") and matching every existing call site — is to merge the prefixed metrics into
output_batchin-place.Fix
dict[str, Any]toNoneso the type matches the runtime behavior.output_batchafter the call.No runtime behavior change.
Verification
grep -A 12 "def run" src/alpamayo_r1/metrics/metric_runner.pyshows the body has noreturnstatement; the only side effect is theoutput_batch.update(...)call on the last line.