1515import re
1616from collections .abc import Hashable , Iterable
1717from dataclasses import dataclass
18- from typing import Any , Literal , Protocol , Self , overload
18+ from typing import Any , Literal , Protocol , Self , cast , overload
1919
2020import xarray as xr
2121
@@ -149,13 +149,13 @@ def __eq__(self, other: Any) -> bool:
149149 return self .to_attrs () == other .to_attrs ()
150150
151151 @classmethod
152- def from_attrs (cls , attrs ):
152+ def from_attrs (cls , attrs ): # type: ignore[override]
153153 try :
154154 return cls (
155155 cf_role = attrs ["cf_role" ],
156156 topology_dimension = attrs ["topology_dimension" ],
157- node_dimensions = load_mappings (attrs ["node_dimensions" ]),
158- face_dimensions = load_mappings (attrs ["face_dimensions" ]),
157+ node_dimensions = cast ( tuple [ Dim , Dim ], load_mappings (attrs ["node_dimensions" ]) ),
158+ face_dimensions = cast ( tuple [ DimDimPadding , DimDimPadding ], load_mappings (attrs ["face_dimensions" ]) ),
159159 node_coordinates = maybe_load_mappings (attrs .get ("node_coordinates" )),
160160 vertical_dimensions = maybe_load_mappings (attrs .get ("vertical_dimensions" )),
161161 )
@@ -176,7 +176,7 @@ def to_attrs(self) -> dict[str, str | int]:
176176 return d
177177
178178 def rename (self , names_dict : dict [str , str ]) -> Self :
179- return _metadata_rename (self , names_dict )
179+ return cast ( Self , _metadata_rename (self , names_dict ) )
180180
181181 def get_value_by_id (self , id : str ) -> str :
182182 """In the SGRID specification for 2D grids, different parts of the spec are identified by different "ID"s.
@@ -262,13 +262,15 @@ def __eq__(self, other: Any) -> bool:
262262 return self .to_attrs () == other .to_attrs ()
263263
264264 @classmethod
265- def from_attrs (cls , attrs ):
265+ def from_attrs (cls , attrs ): # type: ignore[override]
266266 try :
267267 return cls (
268268 cf_role = attrs ["cf_role" ],
269269 topology_dimension = attrs ["topology_dimension" ],
270- node_dimensions = load_mappings (attrs ["node_dimensions" ]),
271- volume_dimensions = load_mappings (attrs ["volume_dimensions" ]),
270+ node_dimensions = cast (tuple [Dim , Dim , Dim ], load_mappings (attrs ["node_dimensions" ])),
271+ volume_dimensions = cast (
272+ tuple [DimDimPadding , DimDimPadding , DimDimPadding ], load_mappings (attrs ["volume_dimensions" ])
273+ ),
272274 node_coordinates = maybe_load_mappings (attrs .get ("node_coordinates" )),
273275 )
274276 except Exception as e :
@@ -286,7 +288,7 @@ def to_attrs(self) -> dict[str, str | int]:
286288 return d
287289
288290 def rename (self , dims_dict : dict [str , str ]) -> Self :
289- return _metadata_rename (self , dims_dict )
291+ return cast ( Self , _metadata_rename (self , dims_dict ) )
290292
291293 def get_value_by_id (self , id : str ) -> str :
292294 """In the SGRID specification for 3D grids, different parts of the spec are identified by different "ID"s.
0 commit comments