@@ -281,7 +281,7 @@ def get_local_defns(boxed: Boxed) -> tuple[dict[str, Any], dict[str, Any]]:
281281 return annos , dct
282282
283283
284- def flatten_class (cls : type ) -> type :
284+ def flatten_class_new_proto (cls : type ) -> type :
285285 # This is a hacky version of flatten_class that works by using
286286 # NewProtocol on Members!
287287 #
@@ -294,8 +294,13 @@ def flatten_class(cls: type) -> type:
294294
295295 type ClsAlias = NewProtocol [* [m for m in Iter [Members [cls ]]]] # type: ignore[valid-type]
296296 nt = _eval_typing .eval_typing (ClsAlias )
297- nt .__name__ = cls .__name__
298- nt .__qualname__ = cls .__qualname__
297+
298+ args = typing .get_args (cls )
299+ args_str = ", " .join (_type_repr (a ) for a in args )
300+ args_str = f'[{ args_str } ]' if args_str else ''
301+
302+ nt .__name__ = f'{ cls .__name__ } { args_str } '
303+ nt .__qualname__ = f'{ cls .__qualname__ } { args_str } '
299304 del nt .__subclasshook__
300305
301306 return nt
@@ -311,8 +316,9 @@ def _type_repr(t: Any) -> str:
311316 return repr (t )
312317
313318
314- # XXX: This is all dead now???
315- def apply (
319+ # TODO: Potentially most of this could be ripped out. The internals
320+ # don't use this at all, it's only used by format_class.
321+ def _flatten_class_explicit (
316322 cls : type [Any ], ctx : _eval_typing .EvalContext
317323) -> type[_eval_typing ._EvalProxy ]:
318324 cls_boxed = box (cls )
@@ -349,7 +355,7 @@ def apply(
349355 "__local_args__" : args ,
350356 },
351357 )
352- ctx . seen [ boxed . alias_type ()] = new [boxed ] = cboxed
358+ new [boxed ] = cboxed
353359
354360 annos : dict [str , Any ] = {}
355361 dct : dict [str , Any ] = {}
@@ -383,3 +389,11 @@ def apply(
383389 setattr (cboxed , k , _eval_typing ._eval_types (v , ctx = ctx ))
384390
385391 return new [cls_boxed ]
392+
393+
394+ def flatten_class_explicit (obj : typing .Any ):
395+ with _eval_typing ._ensure_context () as ctx :
396+ return _flatten_class_explicit (obj , ctx )
397+
398+
399+ flatten_class = flatten_class_explicit
0 commit comments