Skip to content

Commit 04b554d

Browse files
committed
Include args in apply type names
1 parent 79f9f4f commit 04b554d

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

typemap/type_eval/_apply_generic.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,16 @@ def _get_local_defns(boxed: Boxed) -> tuple[dict[str, Any], dict[str, Any]]:
253253
return annos, dct
254254

255255

256+
def _type_repr(t: Any) -> str:
257+
if isinstance(t, type):
258+
if t.__module__ == "builtins":
259+
return t.__qualname__
260+
else:
261+
return f"{t.__module__}.{t.__qualname__}"
262+
else:
263+
return repr(t)
264+
265+
256266
def apply(
257267
cls: type[Any], ctx: _eval_typing.EvalContext
258268
) -> type[_eval_typing._EvalProxy]:
@@ -274,14 +284,18 @@ def apply(
274284
# we stop flattening attributes into every class
275285
name = boxed.cls.__name__
276286
cboxed: Any
287+
288+
args = tuple(boxed.args.values())
289+
args_str = ", ".join(_type_repr(a) for a in args)
290+
fullname = f"{name}[{args_str}]" if args_str else name
277291
cboxed = type(
278-
boxed.cls.__name__,
292+
fullname,
279293
(_eval_typing._EvalProxy,),
280294
{
281295
"__module__": boxed.cls.__module__,
282-
"__name__": name,
296+
"__name__": fullname,
283297
"__origin__": boxed.cls,
284-
"__local_args__": tuple(boxed.args.values()),
298+
"__local_args__": args,
285299
},
286300
)
287301
ctx.seen[boxed.alias_type()] = new[boxed] = cboxed

0 commit comments

Comments
 (0)