Skip to content

Conversation

@marcorudolphflex
Copy link
Contributor

@marcorudolphflex marcorudolphflex commented Nov 10, 2025

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/data folder 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:

  • Added tidy3d/components/data to mypy's checked files in pyproject.toml
  • Imported typing constructs (Self, NDArray, TYPE_CHECKING, InterpolationType, etc.) throughout the data modules
  • Added type hints to methods, properties, validators, and helper functions
  • Used TYPE_CHECKING guards to avoid circular imports with VTK types in unstructured modules
  • Created GRID_CORRECTION_TYPE type alias to simplify complex union types

Issue found:

  • One incorrect type annotation in monitor_data.py:1823 where **kwargs is typed as Optional[Mapping] instead of Any

Confidence Score: 4/5

  • Safe to merge after fixing the one type annotation issue
  • The PR contains well-structured type annotations that improve code maintainability and catch potential type errors. However, there's one incorrect **kwargs type annotation that needs correction before merging to avoid mypy errors
  • tidy3d/components/data/monitor_data.py - fix the _assign_coords type annotation on line 1823

Important Files Changed

File Analysis

Filename Score Overview
tidy3d/components/data/monitor_data.py 3/5 Added comprehensive type hints for function parameters and return types, but contains an incorrect type annotation in _assign_coords
tidy3d/components/data/data_array.py 5/5 Added proper type hints including NDArray, InterpolationType import, and function signatures - clean implementation
tidy3d/components/data/unstructured/base.py 5/5 Added comprehensive type hints with proper use of TYPE_CHECKING, NDArray, and VTK types - well structured
pyproject.toml 5/5 Added tidy3d/components/data to mypy files list for type checking enforcement

Sequence 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
Loading

@marcorudolphflex marcorudolphflex force-pushed the FXC-4061-mypy-implement-type-defs-in-components-data branch 2 times, most recently from f95897a to a8e97dc Compare November 10, 2025 11:47
@marcorudolphflex marcorudolphflex marked this pull request as ready for review November 10, 2025 11:51
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.

12 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@mahlau-flex mahlau-flex force-pushed the yaugenst-flex/pydantic-v2 branch 2 times, most recently from d786339 to 15e431e Compare November 10, 2025 16:05
@marcorudolphflex marcorudolphflex force-pushed the FXC-4061-mypy-implement-type-defs-in-components-data branch from a8e97dc to 2c11697 Compare November 11, 2025 07:33
@mahlau-flex mahlau-flex merged commit db00570 into yaugenst-flex/pydantic-v2 Nov 11, 2025
10 checks passed
@mahlau-flex mahlau-flex deleted the FXC-4061-mypy-implement-type-defs-in-components-data branch November 11, 2025 07: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