diff --git a/foamlib/_files/_parsing.py b/foamlib/_files/_parsing.py index 4b218b1..72d8172 100644 --- a/foamlib/_files/_parsing.py +++ b/foamlib/_files/_parsing.py @@ -89,7 +89,7 @@ def _parse_ascii_field( s = re.sub(ignore.re, " ", s) s = s.replace("(", " ").replace(")", " ") - return np.fromstring(s, sep=" ").reshape(-1, *tensor_kind.shape) + return np.fromstring(s, sep=" ").reshape(-1, *tensor_kind.shape) # type: ignore [return-value] def _unpack_binary_field( @@ -99,7 +99,7 @@ def _unpack_binary_field( assert float_size in (4, 8) dtype = np.float32 if float_size == 4 else float - return np.frombuffer(b, dtype=dtype).reshape(-1, *tensor_kind.shape) + return np.frombuffer(b, dtype=dtype).reshape(-1, *tensor_kind.shape) # type: ignore [return-value] def _tensor_list( diff --git a/foamlib/_files/_serialization.py b/foamlib/_files/_serialization.py index 9e9380f..54fec4d 100644 --- a/foamlib/_files/_serialization.py +++ b/foamlib/_files/_serialization.py @@ -50,7 +50,7 @@ def normalize(data: Entry, *, kind: Kind = Kind.DEFAULT) -> Entry: arr = arr.astype(float) if arr.ndim == 1 or (arr.ndim == 2 and arr.shape[1] in (3, 6, 9)): - return arr + return arr # type: ignore [return-value] return data diff --git a/foamlib/_files/_types.py b/foamlib/_files/_types.py index 8fefa7e..3cb6e41 100644 --- a/foamlib/_files/_types.py +++ b/foamlib/_files/_types.py @@ -79,7 +79,7 @@ class Dimensioned: def __post_init__(self) -> None: if is_sequence(self.value): - self.value = np.asarray(self.value, dtype=float) + self.value = np.asarray(self.value, dtype=float) # type: ignore [assignment] else: assert isinstance(self.value, (int, float, np.ndarray)) self.value = float(self.value) diff --git a/tests/test_files/test_dumps.py b/tests/test_files/test_dumps.py index b7a0b60..90c159a 100644 --- a/tests/test_files/test_dumps.py +++ b/tests/test_files/test_dumps.py @@ -37,7 +37,7 @@ def test_serialize_data() -> None: == b"nonuniform List 2(\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00\x08@\x00\x00\x00\x00\x00\x00\x10@\x00\x00\x00\x00\x00\x00\x14@\x00\x00\x00\x00\x00\x00\x18@)" ) assert ( - dumps(np.array([1, 2], dtype=np.float32), kind=Kind.BINARY_FIELD) + dumps(np.array([1, 2], dtype=np.float32), kind=Kind.BINARY_FIELD) # type: ignore [arg-type] == b"nonuniform List 2(\x00\x00\x80?\x00\x00\x00@)" ) assert ( diff --git a/tests/test_files/test_files.py b/tests/test_files/test_files.py index 964d507..0f88ca9 100644 --- a/tests/test_files/test_files.py +++ b/tests/test_files/test_files.py @@ -163,19 +163,19 @@ def test_internal_field(cavity: FoamCase) -> None: p_arr = np.zeros(size) U_arr = np.zeros((size, 3)) - cavity[0]["p"].internal_field = p_arr - cavity[0]["U"].internal_field = U_arr + cavity[0]["p"].internal_field = p_arr # type: ignore [assignment] + cavity[0]["U"].internal_field = U_arr # type: ignore [assignment] assert cavity[0]["p"].internal_field == pytest.approx(p_arr) U = cavity[0]["U"].internal_field assert isinstance(U, np.ndarray) assert U_arr == pytest.approx(U) - p_arr = np.arange(size) * 1e-6 + p_arr = np.arange(size) * 1e-6 # type: ignore [assignment] U_arr = np.full((size, 3), [-1e-6, 1e-6, 0]) * np.arange(size)[:, np.newaxis] - cavity[0]["p"].internal_field = p_arr - cavity[0]["U"].internal_field = U_arr + cavity[0]["p"].internal_field = p_arr # type: ignore [assignment] + cavity[0]["U"].internal_field = U_arr # type: ignore [assignment] assert cavity[0]["p"].internal_field == pytest.approx(p_arr) U = cavity[0]["U"].internal_field @@ -210,7 +210,7 @@ def test_binary_field(cavity: FoamCase) -> None: p_arr = np.arange(len(p_bin)) * 1e-6 U_arr = np.full_like(U_bin, [-1e-6, 1e-6, 0]) * np.arange(len(U_bin))[:, np.newaxis] - cavity[0]["p"].internal_field = p_arr + cavity[0]["p"].internal_field = p_arr # type: ignore [assignment] cavity[0]["U"].internal_field = U_arr assert cavity[0]["p"].internal_field == pytest.approx(p_arr) @@ -237,7 +237,7 @@ def test_compressed_field(cavity: FoamCase) -> None: p_arr = np.arange(len(p_bin)) * 1e-6 U_arr = np.full_like(U_bin, [-1e-6, 1e-6, 0]) * np.arange(len(U_bin))[:, np.newaxis] - cavity[0]["p"].internal_field = p_arr + cavity[0]["p"].internal_field = p_arr # type: ignore [assignment] cavity[0]["U"].internal_field = U_arr assert cavity[0]["p"].internal_field == pytest.approx(p_arr)