11"""
2- Utils and helpers specific for working with SGrid conventions.
2+ Provides helpers and utils for working with SGrid conventions, as well as data objects
3+ useful for representing the SGRID metadata model in code.
34
5+ This code is best read alongside the SGrid conventions documentation:
46https://sgrid.github.io/sgrid/
7+
8+ Note this code doesn't aim to completely cover the SGrid conventions, but aim to
9+ cover SGrid to the extent to which Parcels is concerned.
510"""
611
712from __future__ import annotations
1015import re
1116from collections .abc import Hashable , Iterable
1217from dataclasses import dataclass
13- from typing import Any , Literal , Protocol , Self , cast , overload
18+ from typing import Any , Literal , Protocol , Self , overload
1419
1520import xarray as xr
1621
@@ -242,16 +247,14 @@ def maybe_dump_mappings(parts):
242247 return dump_mappings (parts )
243248
244249
245- def load_mappings (s : Any ) -> tuple [DimDimPadding | Dim , ...]:
250+ def load_mappings (s : str ) -> tuple [DimDimPadding | Dim , ...]:
246251 """Takes in a string indicating the mappings of dims and dim-dim-padding
247252 and returns a tuple with this data destructured.
248253
249254 Treats `:` and `: ` equivalently (in line with the convention).
250255 """
251256 if not isinstance (s , str ):
252257 raise ValueError (f"Expected string input, got { s !r} of type { type (s )} " )
253- assert isinstance (s , str )
254- cast (str , s ) # encountered a bug in mypy
255258
256259 s = s .replace (": " , ":" )
257260 ret = []
@@ -263,6 +266,7 @@ def load_mappings(s: Any) -> tuple[DimDimPadding | Dim, ...]:
263266 part = match .group (0 )
264267 s_new = s [match .end () :].lstrip ()
265268 else :
269+ # no DimDimPadding match at start, assume just a Dim until next space
266270 part , * s_new = s .split (" " , 1 )
267271 s_new = "" .join (s_new )
268272
0 commit comments