Skip to content

Improve typechecking#2541

Merged
VeckoTheGecko merged 15 commits intoParcels-code:mainfrom
VeckoTheGecko:typechecking
Mar 10, 2026
Merged

Improve typechecking#2541
VeckoTheGecko merged 15 commits intoParcels-code:mainfrom
VeckoTheGecko:typechecking

Conversation

@VeckoTheGecko
Copy link
Contributor

Supercedes #2422

This PR adds a bunch of type annotations to the codebase, and centralises a lot of the types that are shared between files to parcels._typing (which in some places is imported as ptyping which i think is a nice alias).

VeckoTheGecko and others added 15 commits March 10, 2026 18:56
…init__ return type

- Remove 8 unused `# type: ignore` directives from _compat.py,
  particlefile.py, and utils/interpolation.py (now redundant with ty)
- Fix UxGrid.__init__ return annotation from UxGrid to None

Co-authored-by: Claude <noreply@anthropic.com>
Its already handled via runtime validation internally
Here we just rely on the runtime checking - this is unsanitised inputs anyway
Comment on lines -50 to +65
def vectorfield_repr(fieldset: FieldSet, from_fieldset_repr=False) -> str:
def vectorfield_repr(vector_field: VectorField, from_fieldset_repr=False) -> str:
"""Return a pretty repr for VectorField"""
out = f"""<{type(fieldset).__name__} {fieldset.name!r}>
out = f"""<{type(vector_field).__name__} {vector_field.name!r}>
Parcels attributes:
name : {fieldset.name!r}
vector_interp_method : {fieldset.vector_interp_method!r}
vector_type : {fieldset.vector_type!r}
{field_repr(fieldset.U, level=1) if not from_fieldset_repr else ""}
{field_repr(fieldset.V, level=1) if not from_fieldset_repr else ""}
{field_repr(fieldset.W, level=1) if not from_fieldset_repr and fieldset.W else ""}"""
name : {vector_field.name!r}
vector_interp_method : {vector_field.vector_interp_method!r}
vector_type : {vector_field.vector_type!r}
{field_repr(vector_field.U, level=1) if not from_fieldset_repr else ""}
{field_repr(vector_field.V, level=1) if not from_fieldset_repr else ""}
{field_repr(vector_field.W, level=1) if not from_fieldset_repr and vector_field.W else ""}"""
Copy link
Contributor Author

Choose a reason for hiding this comment

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

quick win that was flagged by the typechecking

@VeckoTheGecko VeckoTheGecko enabled auto-merge (squash) March 10, 2026 17:58
@VeckoTheGecko VeckoTheGecko merged commit d38ba97 into Parcels-code:main Mar 10, 2026
11 of 12 checks passed
@github-project-automation github-project-automation bot moved this from Backlog to Done in Parcels development Mar 10, 2026
@VeckoTheGecko VeckoTheGecko deleted the typechecking branch March 10, 2026 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant