2
2
3
3
from collections .abc import Mapping
4
4
from 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
6
6
7
7
import numpy as np
8
8
import typing_extensions
21
21
22
22
23
23
class Crc32cConfig_V2 (TypedDict ):
24
- location : ReadOnly [Literal ["start" , "end" ]]
24
+ location : NotRequired [ ReadOnly [Literal ["start" , "end" ] ]]
25
25
26
26
27
27
class Crc32cConfig_V3 (TypedDict ): ...
@@ -37,9 +37,9 @@ class Crc32cJSON_V3(NamedConfig[Literal["crc32c"], Crc32cConfig_V3]): ...
37
37
def check_json_v2 (data : object ) -> TypeGuard [Crc32cJSON_V2 ]:
38
38
return (
39
39
isinstance (data , Mapping )
40
- and set ( data . keys ()) == { "id" , "location" }
40
+ and "id" in data
41
41
and data ["id" ] == "crc32c"
42
- and data [ "location" ] in ("start" , "end" )
42
+ and data . get ( "location" , "end" ) in ("start" , "end" )
43
43
)
44
44
45
45
@@ -64,7 +64,7 @@ def from_dict(cls, data: dict[str, JSON]) -> Self:
64
64
@classmethod
65
65
def _from_json_v2 (cls , data : CodecJSON ) -> Self :
66
66
if check_json_v2 (data ):
67
- if data [ "location" ] != "end" :
67
+ if data . get ( "location" , "end" ) != "end" :
68
68
raise ValueError ('The crc32c codec only supports the "end" location' )
69
69
return cls ()
70
70
msg = (
0 commit comments