Skip to content

[ENH] Improve type annotations with short_array_type and field defaults #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 23, 2025

Conversation

Leguark
Copy link
Member

@Leguark Leguark commented May 22, 2025

Improved Type Annotations and Serialization Support

[CLN] Hide temp_interpolation_values from repr output

Added repr=False to temp_interpolation_values to prevent it from being displayed in object representations, improving clarity when debugging or logging.

[ENH] Introduce short_array_type for consistent type annotations

Created a reusable short_array_type using Annotated[np.ndarray, numpy_array_short_validator] to standardize array validation across the codebase.

[ENH] Improve CenteredGrid field definitions

  • Replaced manual field initialization with field(init=False) for cleaner dataclass definition
  • Updated type hints to use the new short_array_type and modern Python syntax
  • Improved type annotations for radius to properly support both float and array types

[ENH] Enhance FiniteFaultData serialization support

  • Added proper field definitions with exclusion for non-serializable callable
  • Implemented error handling for deserialized objects with missing implicit functions
  • Updated type annotations to use short_array_type for consistent validation

[ENH] Update GeophysicsInput with proper type annotations

Replaced BackendTensor references with properly annotated numpy arrays using the validation system, improving type safety and serialization support.

Leguark added 5 commits May 21, 2025 12:04
Added `repr=False` to `temp_interpolation_values` to prevent it from being displayed in object representations. This improves clarity and ensures sensitive or non-essential details are not exposed.
Introduced `numpy_array_short_validator` to ensure proper validation for `centers`, `resolution`, and `radius` attributes in the `CenteredGrid` class. This enhances data integrity and enforces stricter input checks.
Replaced raw tensor attributes with `Annotated` numpy arrays for better type validation and integrated a short numpy array validator. This improves code clarity and enforces input validation.
Replaced verbose `Annotated` type definitions with `short_array_type` for cleaner and more consistent code. Improved clarity and added error handling for deserialized implicit functions in `FiniteFaultData`.
@Leguark Leguark changed the title [CLN] Hide temp_interpolation_values from repr output [ENH] Improve type annotations with short_array_type and field defaults May 22, 2025
Copy link
Member Author

Leguark commented May 22, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@Leguark Leguark marked this pull request as ready for review May 22, 2025 09:07
@Leguark Leguark merged commit 2b00acc into main May 23, 2025
2 checks passed
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.

1 participant