Skip to content

Commit 5161b3f

Browse files
committed
Self review
1 parent 649925a commit 5161b3f

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/parcels/_core/sgrid.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
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:
46
https://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

712
from __future__ import annotations
@@ -10,7 +15,7 @@
1015
import re
1116
from collections.abc import Hashable, Iterable
1217
from dataclasses import dataclass
13-
from typing import Any, Literal, Protocol, Self, cast, overload
18+
from typing import Any, Literal, Protocol, Self, overload
1419

1520
import 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

tests/strategies/sgrid.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"""Provides Hypothesis strategies to help testing the parsing and serialization of datasets
22
According to the SGrid conventions.
33
4+
This code is best read alongside the SGrid conventions documentation:
45
https://sgrid.github.io/sgrid/
56
6-
Note that these strategies don't aim to completely cover the SGrid conventions, but aim to
7+
Note this code doesn't aim to completely cover the SGrid conventions, but aim to
78
cover SGrid to the extent to which Parcels is concerned.
89
"""
910

0 commit comments

Comments
 (0)