@@ -68,9 +68,7 @@ def split_at_given_level(
68
68
69
69
70
70
def _get_parser (
71
- cls : Type ,
72
- type_ : TypeAlias ,
73
- parsers : Optional [Dict [type , Callable [[str ], Any ]]] = None ,
71
+ cls : Type , type_ : TypeAlias , parsers : Optional [Dict [type , Callable [[str ], Any ]]] = None ,
74
72
) -> partial :
75
73
"""Attempts to find a parser for a provided type.
76
74
@@ -114,11 +112,7 @@ def get_parser() -> partial:
114
112
assert (
115
113
len (subtypes ) == 1
116
114
), "Lists are allowed only one subtype per PEP specification!"
117
- subtype_parser = _get_parser (
118
- cls ,
119
- subtypes [0 ],
120
- parsers ,
121
- )
115
+ subtype_parser = _get_parser (cls , subtypes [0 ], parsers ,)
122
116
return functools .partial (
123
117
lambda s : list (
124
118
[]
@@ -134,11 +128,7 @@ def get_parser() -> partial:
134
128
assert (
135
129
len (subtypes ) == 1
136
130
), "Sets are allowed only one subtype per PEP specification!"
137
- subtype_parser = _get_parser (
138
- cls ,
139
- subtypes [0 ],
140
- parsers ,
141
- )
131
+ subtype_parser = _get_parser (cls , subtypes [0 ], parsers ,)
142
132
return functools .partial (
143
133
lambda s : set (
144
134
set ({})
@@ -151,12 +141,7 @@ def get_parser() -> partial:
151
141
)
152
142
elif typing .get_origin (type_ ) == tuple :
153
143
subtype_parsers = [
154
- _get_parser (
155
- cls ,
156
- subtype ,
157
- parsers ,
158
- )
159
- for subtype in typing .get_args (type_ )
144
+ _get_parser (cls , subtype , parsers ,) for subtype in typing .get_args (type_ )
160
145
]
161
146
162
147
def tuple_parse (tuple_string : str ) -> Tuple [Any , ...]:
@@ -185,16 +170,8 @@ def tuple_parse(tuple_string: str) -> Tuple[Any, ...]:
185
170
len (subtypes ) == 2
186
171
), "Dict object must have exactly 2 subtypes per PEP specification!"
187
172
(key_parser , val_parser ) = (
188
- _get_parser (
189
- cls ,
190
- subtypes [0 ],
191
- parsers ,
192
- ),
193
- _get_parser (
194
- cls ,
195
- subtypes [1 ],
196
- parsers ,
197
- ),
173
+ _get_parser (cls , subtypes [0 ], parsers ,),
174
+ _get_parser (cls , subtypes [1 ], parsers ,),
198
175
)
199
176
200
177
def dict_parse (dict_string : str ) -> Dict [Any , Any ]:
@@ -254,9 +231,7 @@ def dict_parse(dict_string: str) -> Dict[Any, Any]:
254
231
255
232
256
233
def attr_from (
257
- cls : Type ,
258
- kwargs : Dict [str , str ],
259
- parsers : Optional [Dict [type , Callable [[str ], Any ]]] = None ,
234
+ cls : Type , kwargs : Dict [str , str ], parsers : Optional [Dict [type , Callable [[str ], Any ]]] = None ,
260
235
) -> Any :
261
236
"""Builds an attr class from key-word arguments
262
237
0 commit comments