22
33from collections .abc import Mapping
44from dataclasses import dataclass
5- from typing import TYPE_CHECKING , Literal , TypedDict , TypeGuard , cast , overload
5+ from typing import TYPE_CHECKING , Literal , NotRequired , TypedDict , TypeGuard , cast , overload
66
77import numpy as np
88import typing_extensions
2121
2222
2323class Crc32cConfig_V2 (TypedDict ):
24- location : ReadOnly [Literal ["start" , "end" ]]
24+ location : NotRequired [ ReadOnly [Literal ["start" , "end" ] ]]
2525
2626
2727class Crc32cConfig_V3 (TypedDict ): ...
@@ -37,9 +37,9 @@ class Crc32cJSON_V3(NamedConfig[Literal["crc32c"], Crc32cConfig_V3]): ...
3737def check_json_v2 (data : object ) -> TypeGuard [Crc32cJSON_V2 ]:
3838 return (
3939 isinstance (data , Mapping )
40- and set ( data . keys ()) == { "id" , "location" }
40+ and "id" in data
4141 and data ["id" ] == "crc32c"
42- and data [ "location" ] in ("start" , "end" )
42+ and data . get ( "location" , "end" ) in ("start" , "end" )
4343 )
4444
4545
@@ -64,7 +64,7 @@ def from_dict(cls, data: dict[str, JSON]) -> Self:
6464 @classmethod
6565 def _from_json_v2 (cls , data : CodecJSON ) -> Self :
6666 if check_json_v2 (data ):
67- if data [ "location" ] != "end" :
67+ if data . get ( "location" , "end" ) != "end" :
6868 raise ValueError ('The crc32c codec only supports the "end" location' )
6969 return cls ()
7070 msg = (
0 commit comments