Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some typing #9988

Merged
merged 9 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions xarray/backends/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ def __init__(
self._members = self._fetch_members()

@property
def members(self) -> dict[str, ZarrArray]:
def members(self) -> dict[str, ZarrArray | ZarrGroup]:
"""
Model the arrays and groups contained in self.zarr_group as a dict. If `self._cache_members`
is true, the dict is cached. Otherwise, it is retrieved from storage.
Expand All @@ -778,7 +778,7 @@ def members(self) -> dict[str, ZarrArray]:
else:
return self._members

def _fetch_members(self) -> dict[str, ZarrArray]:
def _fetch_members(self) -> dict[str, ZarrArray | ZarrGroup]:
"""
Get the arrays and groups defined in the zarr group modelled by this Store
"""
Expand Down Expand Up @@ -1066,6 +1066,8 @@ def _open_existing_array(self, *, name) -> ZarrArray:
else:
zarr_array = self.zarr_group[name]

if TYPE_CHECKING:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what the error here was, but simpler use cast(ZarrArray, zarr_array).

assert isinstance(zarr_array, ZarrArray)
return zarr_array

def _create_new_array(
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
try:
from zarr import Array as ZarrArray
except ImportError:
ZarrArray = np.ndarray
ZarrArray = np.ndarray # type: ignore[misc, assignment, unused-ignore]

# Anything that can be coerced to a shape tuple
_ShapeLike = Union[SupportsIndex, Sequence[SupportsIndex]]
Expand Down
Loading