@@ -60,13 +60,17 @@ def split_at_given_level(
60
60
decrease_in_depth += high_level_split .count (char )
61
61
outer_depth_of_split += increase_in_depth - decrease_in_depth
62
62
63
- assert outer_depth_of_split >= 0 , "Unpaired depth character! Likely incorrect output"
63
+ assert (
64
+ outer_depth_of_split >= 0
65
+ ), "Unpaired depth character! Likely incorrect output"
64
66
65
67
current_outer_splits .append (high_level_split )
66
68
if outer_depth_of_split == 0 :
67
69
out_vals .append (split_delim .join (current_outer_splits ))
68
70
current_outer_splits = []
69
- assert outer_depth_of_split == 0 , "Unpaired depth character! Likely incorrect output!"
71
+ assert (
72
+ outer_depth_of_split == 0
73
+ ), "Unpaired depth character! Likely incorrect output!"
70
74
return out_vals
71
75
72
76
@@ -148,7 +152,9 @@ def get_parser() -> partial:
148
152
if s == "{}"
149
153
else [
150
154
subtype_parser (item )
151
- for item in set (split_at_given_level (s [1 :- 1 ], split_delim = "," ))
155
+ for item in set (
156
+ split_at_given_level (s [1 :- 1 ], split_delim = "," )
157
+ )
152
158
]
153
159
)
154
160
)
@@ -174,7 +180,9 @@ def tuple_parse(tuple_string: str) -> Tuple[Any, ...]:
174
180
if len (tuple_string ) == 0 :
175
181
return ()
176
182
else :
177
- val_strings = split_at_given_level (tuple_string , split_delim = "," )
183
+ val_strings = split_at_given_level (
184
+ tuple_string , split_delim = ","
185
+ )
178
186
return tuple (
179
187
parser (val_str )
180
188
for parser , val_str in zip (subtype_parsers , val_strings )
@@ -210,10 +218,14 @@ def dict_parse(dict_string: str) -> Dict[Any, Any]:
210
218
if len (dict_string ) == 0 :
211
219
return {}
212
220
else :
213
- outer_splits = split_at_given_level (dict_string , split_delim = "," )
221
+ outer_splits = split_at_given_level (
222
+ dict_string , split_delim = ","
223
+ )
214
224
out_dict = {}
215
225
for outer_split in outer_splits :
216
- inner_splits = split_at_given_level (outer_split , split_delim = ";" )
226
+ inner_splits = split_at_given_level (
227
+ outer_split , split_delim = ";"
228
+ )
217
229
assert (
218
230
len (inner_splits ) % 2 == 0
219
231
), "Inner splits of dict didn't have matched key val pairs"
@@ -228,17 +240,23 @@ def dict_parse(dict_string: str) -> Dict[Any, Any]:
228
240
return types .make_enum_parser (type_ )
229
241
elif types .is_constructible_from_str (type_ ):
230
242
return functools .partial (type_ )
231
- elif type_ is type (None ): # type: ignore[E721]
243
+ elif type_ is type (None ): # type: ignore
232
244
return functools .partial (types .none_parser )
233
245
elif types .get_origin_type (type_ ) is Union :
234
246
return types .make_union_parser (
235
247
union = type_ ,
236
- parsers = [_get_parser (cls , arg , parsers ) for arg in types .get_arg_types (type_ )],
248
+ parsers = [
249
+ _get_parser (cls , arg , parsers )
250
+ for arg in types .get_arg_types (type_ )
251
+ ],
237
252
)
238
253
elif types .get_origin_type (type_ ) is Literal : # Py>=3.7.
239
254
return types .make_literal_parser (
240
255
type_ ,
241
- [_get_parser (cls , type (arg ), parsers ) for arg in types .get_arg_types (type_ )],
256
+ [
257
+ _get_parser (cls , type (arg ), parsers )
258
+ for arg in types .get_arg_types (type_ )
259
+ ],
242
260
)
243
261
else :
244
262
raise ParserNotFoundException (
@@ -293,7 +311,11 @@ def attr_from(
293
311
# try setting by casting
294
312
# Note that while bools *can* be cast from string, all non-empty strings evaluate to
295
313
# True, because python, so we need to check for that explicitly
296
- if not set_value and attribute .type is not None and not attribute .type == bool :
314
+ if (
315
+ not set_value
316
+ and attribute .type is not None
317
+ and not attribute .type == bool
318
+ ):
297
319
try :
298
320
return_value = attribute .type (str_value )
299
321
set_value = True
0 commit comments