@@ -240,22 +240,20 @@ def convert_union_type(
240
240
Convert an annotated Python Union type into a Graphene Union.
241
241
"""
242
242
inner_types = type_ .__args__
243
- if len (inner_types ) == 2 and NONE_TYPE in inner_types :
244
- # This is effectively a typing.Optional[T], which decomposes into a
245
- # typing.Union[None, T] -- we can return the Graphene type for T directly
246
- # since Pydantic will have already parsed it as optional
247
- native_type = next (x for x in inner_types if x != NONE_TYPE ) # noqa: E721
248
- graphene_type = find_graphene_type (
249
- native_type , field , registry , parent_type = parent_type , model = model
250
- )
251
- return graphene_type
252
-
253
- # Otherwise, we use a little metaprogramming -- create our own unique
243
+ # We use a little metaprogramming -- create our own unique
254
244
# subclass of graphene.Union that knows its constituent Graphene types
255
245
parent_types = tuple (
256
246
find_graphene_type (x , field , registry , parent_type = parent_type , model = model )
257
247
for x in inner_types
248
+ if x != NONE_TYPE
258
249
)
250
+
251
+ # This is effectively a typing.Optional[T], which decomposes into a
252
+ # typing.Union[None, T] -- we can return the Graphene type for T directly
253
+ # since Pydantic will have already parsed it as optional
254
+ if len (parent_types ) == 1 :
255
+ return parent_types [0 ]
256
+
259
257
internal_meta_cls = type ("Meta" , (), {"types" : parent_types })
260
258
261
259
union_cls = type (
0 commit comments