Skip to content

Commit d42e0e6

Browse files
committed
add enter and exit methods to groups.
1 parent 678b2e8 commit d42e0e6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/zarr/core/group.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import warnings
88
from collections import defaultdict
99
from dataclasses import asdict, dataclass, field, fields, replace
10-
from typing import TYPE_CHECKING, Literal, TypeVar, assert_never, cast, overload
10+
from typing import TYPE_CHECKING, Literal, TypeVar, assert_never, cast, overload, Self
1111

1212
import numpy as np
1313
import numpy.typing as npt
@@ -1752,6 +1752,12 @@ def open(
17521752
obj = sync(AsyncGroup.open(store, zarr_format=zarr_format))
17531753
return cls(obj)
17541754

1755+
def __enter__(self) -> Self:
1756+
return self
1757+
1758+
def __exit__(self) -> None: # noqa: PYI036
1759+
self.store.close()
1760+
17551761
def __getitem__(self, path: str) -> Array | Group:
17561762
"""Obtain a group member.
17571763

0 commit comments

Comments
 (0)