Skip to content

Commit

Permalink
Improve typing readability.
Browse files Browse the repository at this point in the history
  • Loading branch information
trexfeathers committed Apr 2, 2024
1 parent aa80493 commit 9a186b8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/iris/fileformats/netcdf/saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ class VariableEmulator(typing.Protocol):
_data_array: np.typing.ArrayLike


CFVariable: typing.TypeAlias = typing.Union[
_thread_safe_nc.VariableWrapper, VariableEmulator
]


class Saver:
"""A manager for saving netcdf files."""

Expand Down Expand Up @@ -2288,7 +2293,7 @@ def _increment_name(self, varname):
def _lazy_stream_data(
self,
data: np.typing.ArrayLike,
cf_var: typing.Union[_thread_safe_nc.VariableWrapper, VariableEmulator],
cf_var: CFVariable,
) -> None:
if hasattr(data, "shape") and data.shape == (1,) + cf_var.shape:
# (Don't do this check for string data).
Expand All @@ -2315,9 +2320,7 @@ def _lazy_stream_data(
# later by a call to delayed_completion().
def store(
data: np.typing.ArrayLike,
cf_var: typing.Union[
_thread_safe_nc.VariableWrapper, VariableEmulator
],
cf_var: CFVariable,
) -> None:
# Create a data-writeable object that we can stream into, which
# encapsulates the file to be opened + variable to be written.
Expand All @@ -2331,9 +2334,7 @@ def store(
# Real data is always written directly, i.e. not via lazy save.
def store(
data: np.typing.ArrayLike,
cf_var: typing.Union[
_thread_safe_nc.VariableWrapper, VariableEmulator
],
cf_var: CFVariable,
) -> None:
cf_var[:] = data

Expand Down

0 comments on commit 9a186b8

Please sign in to comment.