FXC-3795 improving type hints for Tidy3dBaseModel #2919
Merged
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.
Testing out better type hints for these commonly used method, especially
updated_copyGreptile Overview
Updated On: 2025-10-22 14:25:57 UTC
Greptile Summary
This PR modernizes type hints in
Tidy3dBaseModelby replacing explicitTidy3dBaseModelreturn types with theSelftype fromtyping_extensions. This affects 11 methods includingcopy(),updated_copy(), and severalfrom_*()classmethods. The change enables type checkers to correctly infer that when a subclass (e.g.,Simulation,Structure) calls these methods, they return instances of the subclass rather than the base class. This improves IDE autocomplete, catches type errors earlier, and follows modern Python typing best practices. SinceSelfis a pure type-checking construct available viatyping_extensions, this change has zero runtime impact and maintains full backward compatibility while significantly improving the developer experience across the entire Tidy3D codebase.Changed Files
Tidy3dBaseModeltoSelffor 11 methods to improve type inference for subclassesConfidence score: 5/5
Selfis a pure type-checking construct with zero runtime behavior changes and is fully compatible with pydantic v1 viatyping_extensions