Skip to content

Commit 5d4d09a

Browse files
committed
typing
1 parent b57ed72 commit 5d4d09a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/zarr/v3/common.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,19 @@ async def to_thread(func, /, *args, **kwargs):
6464
return await loop.run_in_executor(None, func_call)
6565

6666

67-
def enum_names(enum: Enum) -> Iterator[str]:
68-
for item in enum:
69-
yield item.name
67+
E = TypeVar("E", bound=Enum)
7068

7169

72-
E = TypeVar("E", bound=Enum)
70+
def enum_names(enum: Type[E]) -> Iterator[str]:
71+
for item in enum:
72+
yield item.name
7373

7474

7575
def parse_enum(data: JSON, cls: Type[E]) -> E:
7676
if isinstance(data, cls):
7777
return data
78+
if not isinstance(data, str):
79+
raise TypeError(f"Expected str, got {type(data)}")
7880
if data in enum_names(cls):
7981
return cls(data)
8082
raise ValueError(f"Value must be one of {repr(list(enum_names(cls)))}. Got {data} instead.")

0 commit comments

Comments
 (0)