@@ -50,6 +50,9 @@ def is_array_type(storage_type: type[Any]) -> bool:
50
50
51
51
def get_list_elt_type (list_type : type [Any ]) -> type [Any ]:
52
52
"""Extract list item type from list type"""
53
+ if list_type is Any :
54
+ return type (Any )
55
+
53
56
# NOTE: regular list
54
57
if get_origin (list_type ) == list : # noqa: E721
55
58
return get_args (list_type )[0 ] # type: ignore[no-any-return]
@@ -61,6 +64,9 @@ def get_list_elt_type(list_type: type[Any]) -> type[Any]:
61
64
62
65
def get_dict_value_type (dict_type : type [Any ], key : str | None = None ) -> type [Any ]:
63
66
"""Extract dict value types from field type"""
67
+ if dict_type is Any :
68
+ return type (Any )
69
+
64
70
# NOTE: Regular dict
65
71
if get_origin (dict_type ) == dict : # noqa: E721
66
72
return get_args (dict_type )[1 ] # type: ignore[no-any-return]
@@ -78,7 +84,10 @@ def get_dict_value_type(dict_type: type[Any], key: str | None = None) -> type[An
78
84
if key in (name , field .alias ):
79
85
return field .annotation # type: ignore[no-any-return]
80
86
81
- # NOTE: Either we try the wrong Union path or model was modifier by user
87
+ if dict_type .model_config ['extra' ] in ('ignore' , 'allow' ):
88
+ return dict_type
89
+
90
+ # NOTE: Either we tried wrong Union path or model was modifier by user
82
91
raise KeyError (f'Field `{ key } ` not found in { dict_type } ' )
83
92
84
93
@@ -114,18 +123,26 @@ def _apply_bigmap_diffs(
114
123
) -> list [dict [str , Any ]] | dict [str , Any ]:
115
124
"""Apply bigmap diffs to the storage"""
116
125
diffs = bigmap_diffs .get (bigmap_id , ())
117
- diffs_items = ((d ['content' ]['key' ], d ['content' ]['value' ]) for d in diffs )
118
126
119
- if is_array :
120
- list_storage : list [dict [str , Any ]] = []
121
- for key , value in diffs_items :
127
+ list_storage : list [dict [str , Any ]] = []
128
+ dict_storage : dict [str , Any ] = {}
129
+
130
+ for item in diffs :
131
+ key , value = item ['content' ]['key' ], item ['content' ]['value' ]
132
+
133
+ if is_array :
134
+ list_storage .append ({'key' : key , 'value' : value })
135
+ continue
136
+ try :
137
+ dict_storage [key ] = value
138
+ except TypeError :
122
139
list_storage .append ({'key' : key , 'value' : value })
123
- return list_storage
140
+ else :
141
+ return list_storage if is_array else dict_storage
124
142
125
- dict_storage : dict [str , Any ] = {}
126
- for key , value in diffs_items :
127
- dict_storage [key ] = value
128
- return dict_storage
143
+ if list_storage and dict_storage :
144
+ raise Exception
145
+ return list_storage or dict_storage
129
146
130
147
131
148
def _process_storage (
0 commit comments