Skip to content

add enter and exit methods to groups. #2691

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion src/zarr/core/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import warnings
from collections import defaultdict
from dataclasses import asdict, dataclass, field, fields, replace
from typing import TYPE_CHECKING, Literal, TypeVar, assert_never, cast, overload
from typing import TYPE_CHECKING, Literal, TypeVar, assert_never, cast, overload, Self

import numpy as np
import numpy.typing as npt
Expand Down Expand Up @@ -1752,6 +1752,12 @@
obj = sync(AsyncGroup.open(store, zarr_format=zarr_format))
return cls(obj)

def __enter__(self) -> Self:
return self

Check warning on line 1756 in src/zarr/core/group.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/core/group.py#L1756

Added line #L1756 was not covered by tests

def __exit__(self) -> None: # noqa: PYI036
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def __exit__(self) -> None: # noqa: PYI036
def __exit__(
self,
typ: type[BaseException] | None,
exc: BaseException | None,
tb: TracebackType | None
) -> None:

See https://docs.astral.sh/ruff/rules/bad-exit-annotation/

Copy link
Author

Choose a reason for hiding this comment

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

updated in d8f7d68. Also added tests.

self.store.close()

Check warning on line 1759 in src/zarr/core/group.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/core/group.py#L1759

Added line #L1759 was not covered by tests

def __getitem__(self, path: str) -> Array | Group:
"""Obtain a group member.

Expand Down
Loading