File tree 1 file changed +7
-9
lines changed
src/hayhooks/server/utils
1 file changed +7
-9
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,13 @@ def _handle_generics(t_) -> GenericAlias:
26
26
else :
27
27
result = t
28
28
child_typing .append (result )
29
- return GenericAlias (get_origin (t_ ), tuple (child_typing ))
29
+
30
+ if len (child_typing ) == 2 and child_typing [1 ] is type (None ):
31
+ # because TypedDict can't handle union types with None
32
+ # rewrite them as Optional[type]
33
+ return Optional [child_typing [0 ]]
34
+ else :
35
+ return GenericAlias (get_origin (t_ ), tuple (child_typing ))
30
36
31
37
if isclass (type_ ):
32
38
new_type = {}
@@ -35,14 +41,6 @@ def _handle_generics(t_) -> GenericAlias:
35
41
new_type [arg_name ] = _handle_generics (arg_type )
36
42
else :
37
43
new_type [arg_name ] = arg_type
38
- if new_type :
39
- # because TypedDict can't handle union types with None
40
- # rewrite them as Optional[type]
41
- for arg_name , arg_type in new_type .items ():
42
- type_args = get_args (arg_type )
43
- if len (type_args ) == 2 and type_args [1 ] is type (None ):
44
- new_type [arg_name ] = Optional [type_args [0 ]]
45
- return TypedDict (type_ .__name__ , new_type )
46
44
47
45
return type_
48
46
You can’t perform that action at this time.
0 commit comments