chore(tidy3d): FXC-4301 Add mypy typedefs in components/{autograd, grid, mode, viz} #3020
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.
Greptile Overview
Greptile Summary
This PR adds comprehensive mypy type annotations to four component subpackages:
autograd,grid,mode, andviz. The changes enable strict type checking for these modules by adding them to the mypy configuration inpyproject.toml.Key Changes
ArrayFloat,ArrayComplex, andCoordsTupletype aliases for cleaner numpy array annotationsValidationInfoandSerializationInfotypesParamSpec,TypeVar, andSelffor generic decorators and method chainingIssues Found
grid_spec.py:1866- Type annotation useslistinstead oftuplefor boundaries parametertransforms.py:118- Tuple generator creates variable-length tuple instead of fixed-lengthCoordsTupleConfidence Score: 4/5
grid_spec.pyand tuple generator type mismatch intransforms.py. These are straightforward fixes that should be addressed before merging.tidy3d/components/grid/grid_spec.py(boundaries type) andtidy3d/components/mode/transforms.py(tuple construction)Important Files Changed
File Analysis
_process_sliceboundaries parameter (should be tuple not list)Sequence Diagram
sequenceDiagram participant Dev as Developer participant MyPy as MyPy Type Checker participant Auto as autograd/* participant Grid as grid/* participant Mode as mode/* participant Viz as viz/* Dev->>MyPy: Run mypy on subpackages Note over MyPy: Check pyproject.toml config MyPy->>Auto: Type check autograd/ Auto-->>MyPy: boxes.py ✓ types.py ✓ utils.py ✓ derivative_utils.py ✓ MyPy->>Grid: Type check grid/ Grid-->>MyPy: corner_finder.py ✓ mesher.py ✓ grid.py ✓ Grid-->>MyPy: grid_spec.py ✗ (boundaries: list should be tuple) MyPy->>Mode: Type check mode/ Mode-->>MyPy: derivatives.py ✓ mode_solver.py ✓ simulation.py ✓ solver.py ✓ Mode-->>MyPy: transforms.py ✗ (tuple generator type mismatch) MyPy->>Viz: Type check viz/ Viz-->>MyPy: axes_utils.py ✓ descartes.py ✓ plot_params.py ✓ Viz-->>MyPy: plot_sim_3d.py ✓ visualization_spec.py ✓ MyPy-->>Dev: Report 2 type errors to fix