Repository navigation
Fix type hints in unified_bridge with casts - #1493
Merged
Merged
Conversation
Cast self.legacy to the concrete legacy processor where bridges read its attributes, the impute strategy to ImputeMethod, the checked tensor shape to tuple[int, ...], and the registered bridge class and converting processors to their real types. Build StageNet's token tuple per branch so offsets is never possibly unbound. pyright now reports no errors.
Collaborator
Author
|
/review |
Test CoverageTotal: 83.63% (37321 / 44625 lines)
Workflow run · b1e6c86 |
There was a problem hiding this comment.
AI Review
suggestion: approve
decision: approve
Thank you for this PR. It clears all 13 pyright errors in pyhealth/processors/unified_bridge.py with type-only casts and doesn't change behavior.
I checked each change against the diff:
- Casts: Each cast matches the processor its bridge wraps. The
ImputeMethodcast is only a type annotation. StageNetToUnifiedBridge.transform_batch: Buildingheadin each branch returns the same tuples as before and removes the possibly-unboundoffsets.transform_processorandtransform_batch: The casts only inform the type checker.- Scope: The PR adds no new components, no links between components and no datasets, and it contains nothing unrelated.
- Coverage:
unified_bridge.pyis at 99.2%, above the 80% bar for a changed file. The whole repository is at 83.63%, above the 60% bar. - Tests: The existing tests and doctests passed (123 passed), which is enough since behavior is unchanged.
It looks ready to merge.
Optional suggestion: you could type self.legacy once per bridge class, for example with a class-level annotation. That would avoid repeating the casts at each use site. This is only a style choice and isn't required.
Reviewed commit b1e6c86
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.
pyright reported 13 errors in
pyhealth/processors/unified_bridge.py. This change fixes all of them with casts. It does not change behavior.self.legacyis typed asLegacyFeatureProcessor, so its processor-specific attributes were unknown. It is now cast to the processor each bridge wraps:StageNetProcessor(_is_nested)TimeseriesProcessor(n_features,missing_indicators)TensorProcessor(missing_indicators)TimeseriesProcessor.impute_strategyis a plainstr. It is now cast toImputeMethodfor the level'simpute.TensorProcessor._shapeitems areint | None. The bridge has already ruled outNoneat that point, so they are cast totuple[int, ...].transform_processor, the bridge class is cast toCallable[[LegacyFeatureProcessor], UnifiedBridge].transform_batchcastsprocessors[key]toUnifiedBridge. It only does this for keys that passed theisinstancecheck.StageNetToUnifiedBridge.transform_batchnow builds its token tuple in each branch, sooffsetscan no longer be unbound. It returns the same tuples as before.Testing: pyright reports 0 errors on the file.
tests/**/test_unified_bridge.pyand the module's doctests pass (123 passed).