Skip to content

Conversation

@marcorudolphflex
Copy link
Contributor

@marcorudolphflex marcorudolphflex commented Nov 24, 2025

Greptile Overview

Greptile Summary

This PR adds comprehensive mypy type annotations to four component subpackages: autograd, grid, mode, and viz. The changes enable strict type checking for these modules by adding them to the mypy configuration in pyproject.toml.

Key Changes

  • Type aliases: Added ArrayFloat, ArrayComplex, and CoordsTuple type aliases for cleaner numpy array annotations
  • Function signatures: Added complete type hints to parameters and return values across ~450 lines of code
  • TYPE_CHECKING guards: Used conditional imports to avoid circular dependencies and runtime overhead
  • Pydantic v2 compatibility: Updated validators with proper ValidationInfo and SerializationInfo types
  • Advanced typing: Used ParamSpec, TypeVar, and Self for generic decorators and method chaining
  • Sparse matrices: Added proper scipy sparse matrix type hints in mode solver code

Issues Found

  • grid_spec.py:1866 - Type annotation uses list instead of tuple for boundaries parameter
  • transforms.py:118 - Tuple generator creates variable-length tuple instead of fixed-length CoordsTuple

Confidence Score: 4/5

  • This PR is mostly safe to merge with two minor type annotation corrections needed
  • Score reflects comprehensive type annotation work that is generally correct and well-structured, but contains two syntax errors that will cause mypy failures: incorrect list vs tuple type in grid_spec.py and tuple generator type mismatch in transforms.py. These are straightforward fixes that should be addressed before merging.
  • Pay close attention to tidy3d/components/grid/grid_spec.py (boundaries type) and tidy3d/components/mode/transforms.py (tuple construction)

Important Files Changed

File Analysis

Filename Score Overview
tidy3d/components/autograd/derivative_utils.py 5/5 Added comprehensive type annotations for derivative computations including ArrayFloat/ArrayComplex type aliases and Callable type hints
tidy3d/components/grid/grid_spec.py 3/5 Added extensive type annotations for grid specifications; contains type error in _process_slice boundaries parameter (should be tuple not list)
tidy3d/components/mode/mode_solver.py 5/5 Added comprehensive type annotations including ParamSpec/TypeVar for decorators and Self for model validators
tidy3d/components/mode/solver.py 5/5 Added detailed type annotations for eigenvalue solver including sparse matrices, array types, and literal types for precision/direction
tidy3d/components/mode/transforms.py 4/5 Added type annotations for coordinate transformations; contains type mismatch at line 118 where tuple generator should be explicit tuple construction

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
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

19 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@marcorudolphflex marcorudolphflex force-pushed the FXC-4301-add-mypy-typedefs-in-components-subpackages-autograd-grid-mode-and-viz branch from 3f17c74 to 66bff27 Compare November 24, 2025 14:18
@marcorudolphflex marcorudolphflex force-pushed the FXC-4301-add-mypy-typedefs-in-components-subpackages-autograd-grid-mode-and-viz branch from 66bff27 to af00a5b Compare November 25, 2025 08:47
@marcorudolphflex marcorudolphflex merged commit de35229 into yaugenst-flex/pydantic-v2 Nov 25, 2025
@marcorudolphflex marcorudolphflex deleted the FXC-4301-add-mypy-typedefs-in-components-subpackages-autograd-grid-mode-and-viz branch November 25, 2025 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants