@@ -159,12 +159,26 @@ def make_func(
159159 return new_func
160160
161161
162- def apply (cls : type [Any ]) -> dict [str , Any ]:
162+ def apply (
163+ cls : type [Any ], ctx : _eval_typing .EvalContext
164+ ) -> type [_eval_typing ._EvalProxy ]:
163165 mro_boxed = compute_mro (cls )
164166
165167 annos : dict [str , Any ] = {}
166168 dct : dict [str , Any ] = {}
167169
170+ # We create it early so we can add it to seen, to handle recursion
171+ ctx .seen [cls ] = ret = type (
172+ cls .__name__ ,
173+ (_eval_typing ._EvalProxy ,),
174+ {
175+ "__module__" : cls .__module__ ,
176+ "__name__" : cls .__name__ ,
177+ "__origin__" : cls ,
178+ },
179+ )
180+
181+ # Run through the mro
168182 for boxed in reversed (mro_boxed ):
169183 if af := getattr (boxed .cls , "__annotate__" , None ):
170184 # Class has annotations, let's resolve generic arguments
@@ -235,11 +249,15 @@ def apply(cls: type[Any]) -> dict[str, Any]:
235249 dct [name ] = stuff
236250
237251 for k , v in annos .items ():
238- annos [k ] = _eval_typing .eval_typing ( v )
252+ annos [k ] = _eval_typing ._eval_types ( v , ctx = ctx )
239253
240254 for k , v in dct .items ():
241- dct [k ] = _eval_typing .eval_typing ( v )
255+ dct [k ] = _eval_typing ._eval_types ( v , ctx = ctx )
242256
243257 dct ["__annotations__" ] = annos
244258 dct ["__generalized_mro__" ] = mro_boxed
245- return dct
259+
260+ for k , v in dct .items ():
261+ setattr (ret , k , v )
262+
263+ return ret
0 commit comments