22
33import functools
44import warnings
5+ from contextlib import contextmanager
56from typing import TYPE_CHECKING , Any , TypeVar
67
8+ import zarr
9+
710if TYPE_CHECKING :
8- from collections .abc import Callable
11+ from collections .abc import Callable , Generator
12+
13+ from zarr import Array , Group
14+ from zarr .core .common import (
15+ AccessModeLiteral ,
16+ )
17+ from zarr .storage import StoreLike
918
1019RT = TypeVar ("RT" )
1120
1221
1322# these two functions should be removed and imported from spatialdata._utils once the multi_table branch, which
1423# introduces them, is merged
15- def deprecation_alias (** aliases : str ) -> Callable [[Callable [..., RT ]], Callable [..., RT ]]:
24+ def deprecation_alias (
25+ ** aliases : str ,
26+ ) -> Callable [[Callable [..., RT ]], Callable [..., RT ]]:
1627 """Decorate a function to warn user of use of arguments set for deprecation.
1728
1829 Parameters
@@ -52,7 +63,12 @@ def wrapper(*args: Any, **kwargs: Any) -> RT:
5263 return deprecation_decorator
5364
5465
55- def rename_kwargs (func_name : str , kwargs : dict [str , Any ], aliases : dict [str , str ], class_name : None | str ) -> None :
66+ def rename_kwargs (
67+ func_name : str ,
68+ kwargs : dict [str , Any ],
69+ aliases : dict [str , str ],
70+ class_name : None | str ,
71+ ) -> None :
5672 """Rename function arguments set for deprecation and gives warning in case of usage of these arguments."""
5773 for alias , new in aliases .items ():
5874 if alias in kwargs :
@@ -71,3 +87,17 @@ def rename_kwargs(func_name: str, kwargs: dict[str, Any], aliases: dict[str, str
7187 stacklevel = 3 ,
7288 )
7389 kwargs [new ] = kwargs .pop (alias )
90+
91+
92+ # workaround until https://github.com/zarr-developers/zarr-python/issues/2619 is closed
93+ @contextmanager
94+ def zarr_open (
95+ store : StoreLike | None = None ,
96+ * ,
97+ mode : AccessModeLiteral | None = None ,
98+ ) -> Generator [Array | Group , Any , None ]:
99+ f = zarr .open (store = store , mode = mode )
100+ try :
101+ yield f
102+ finally :
103+ f .store .close ()
0 commit comments