22from abc import ABC , abstractmethod
33from inspect import isabstract
44from contextlib import suppress
5- from itertools import chain
5+ from itertools import chain , product
66from functools import cache
77
88from ..convert import *
@@ -202,6 +202,7 @@ def remove_classes(types: list):
202202
203203 return tuple ({a :0 for a in r })
204204
205+
205206 if isinstance (input_type , str ):
206207 raise TypeError (
207208 f"Provided type '{ input_type } ' is not a type - it is a string!\n "
@@ -217,20 +218,20 @@ def remove_classes(types: list):
217218 # Unpack Union items into a tuple
218219 if origin is Union or issubclass_noexcept (origin , (Iterable , Generic )):
219220 new_types = []
220- for type_ in chain . from_iterable ([ cls . convert_types ( r ) for r in get_args (input_type )] ):
221- new_types .append (type_ )
221+ for arg_group in get_args (input_type ):
222+ new_types .append (remove_classes ( list ( cls . convert_types ( arg_group ))) )
222223
223- new_types = remove_classes (new_types )
224224 if origin is Union :
225- return new_types # Just expand unions
225+ return tuple ( chain . from_iterable ( new_types )) # Just expand unions
226226
227227 # Process abstract classes and polymorphism
228228 new_origins = []
229229 for origin in cls .convert_types (origin ):
230230 if issubclass_noexcept (origin , Iterable ):
231- new_origins .append (origin [tuple (new_types )])
231+ new_origins .append (origin [tuple (chain . from_iterable ( new_types ) )])
232232 elif issubclass_noexcept (origin , Generic ):
233- new_origins .append (origin [tuple (new_types [:len (origin .__parameters__ )])])
233+ for comb in product (* new_types ):
234+ new_origins .append (origin [comb ])
234235 else :
235236 new_origins .append (origin )
236237
0 commit comments