@@ -68,11 +68,12 @@ class AnalyzedTypeInfo:
68
68
Analyzed info of a Python type.
69
69
"""
70
70
kind : str
71
- vector_info : VectorInfo | None # For Vector
72
- elem_type : ElementType | None # For Vector, Table, and Union
71
+ vector_info : VectorInfo | None # For Vector
72
+ elem_type : ElementType | None # For Vector, and Table
73
+ union_variant_types : list [type ] | None # For Union
73
74
74
- key_type : type | None # For element of KTable
75
- struct_type : type | None # For Struct, a dataclass or namedtuple
75
+ key_type : type | None # For element of KTable
76
+ struct_type : type | None # For Struct, a dataclass or namedtuple
76
77
77
78
attrs : dict [str , Any ] | None
78
79
nullable : bool = False
@@ -113,6 +114,7 @@ def analyze_type_info(t) -> AnalyzedTypeInfo:
113
114
114
115
struct_type = None
115
116
elem_type = None
117
+ union_variant_types = None
116
118
key_type = None
117
119
if _is_struct_type (t ):
118
120
struct_type = t
@@ -155,7 +157,7 @@ def analyze_type_info(t) -> AnalyzedTypeInfo:
155
157
return result
156
158
157
159
kind = 'Union'
158
- elem_type = typing . Union [ * non_none_types ]
160
+ union_variant_types = non_none_types
159
161
elif kind is None :
160
162
if t is bytes :
161
163
kind = 'Bytes'
@@ -182,6 +184,7 @@ def analyze_type_info(t) -> AnalyzedTypeInfo:
182
184
kind = kind ,
183
185
vector_info = vector_info ,
184
186
elem_type = elem_type ,
187
+ union_variant_types = union_variant_types ,
185
188
key_type = key_type ,
186
189
struct_type = struct_type ,
187
190
attrs = attrs ,
@@ -236,7 +239,7 @@ def _encode_type(type_info: AnalyzedTypeInfo) -> dict[str, Any]:
236
239
if type_info .elem_type is not types .UnionType :
237
240
raise ValueError ("Union type must have a union-typed element type" )
238
241
encoded_type ['types' ] = [
239
- _encode_type (analyze_type_info (typ )) for typ in typing . get_args ( type_info .elem_type )
242
+ _encode_type (analyze_type_info (typ )) for typ in type_info .union_variant_types
240
243
]
241
244
242
245
elif type_info .kind in TABLE_TYPES :
0 commit comments