FXC-4061 mypy implement type defs in components data #2979
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.
This PR adds typedefs for mypy to the files in the components/data folder.
Greptile Overview
Updated On: 2025-11-10 11:55:19 UTC
Greptile Summary
This PR adds comprehensive type annotations to the
tidy3d/components/datafolder to enable mypy type checking. The changes include adding type hints for function parameters, return types, and internal variables across data array, dataset, monitor data, simulation data, and unstructured grid modules.Key changes:
tidy3d/components/datato mypy's checked files inpyproject.tomlSelf,NDArray,TYPE_CHECKING,InterpolationType, etc.) throughout the data modulesTYPE_CHECKINGguards to avoid circular imports with VTK types in unstructured modulesGRID_CORRECTION_TYPEtype alias to simplify complex union typesIssue found:
monitor_data.py:1823where**kwargsis typed asOptional[Mapping]instead ofAnyConfidence Score: 4/5
**kwargstype annotation that needs correction before merging to avoid mypy errors_assign_coordstype annotation on line 1823Important Files Changed
File Analysis
_assign_coordstidy3d/components/datato mypy files list for type checking enforcementSequence Diagram
sequenceDiagram participant pyproject as pyproject.toml participant mypy as mypy type checker participant data_array as data_array.py participant monitor_data as monitor_data.py participant unstructured as unstructured/base.py participant autograd as autograd/types.py Note over pyproject: Added tidy3d/components/data<br/>to mypy files list pyproject->>mypy: Enable type checking for data modules Note over data_array: Import NDArray, InterpolationType<br/>Add type hints to methods data_array->>autograd: Import InterpolationType autograd-->>data_array: Literal["nearest", "linear"] Note over monitor_data: Add type hints to validators,<br/>properties, and methods monitor_data->>data_array: Use DataArray types monitor_data->>autograd: Import type definitions Note over unstructured: Use TYPE_CHECKING for VTK<br/>Add comprehensive type hints unstructured->>data_array: Use DataArray types mypy->>data_array: Type check mypy->>monitor_data: Type check (⚠️ kwargs issue) mypy->>unstructured: Type check