@@ -839,6 +839,14 @@ def _indirection_key(path: Indirection) -> tuple[str, ...]:
839839 SchemaPath ("std" , "multirange" ),
840840 }
841841)
842+ COLLECTION_TYPES = frozenset (
843+ {
844+ SchemaPath ("std" , "array" ),
845+ SchemaPath ("std" , "tuple" ),
846+ SchemaPath ("std" , "range" ),
847+ SchemaPath ("std" , "multirange" ),
848+ }
849+ )
842850
843851PSEUDO_TYPES = frozenset (("anytuple" , "anyobject" , "anytype" ))
844852
@@ -2517,7 +2525,17 @@ def write_generic_types(
25172525 suggested_module_alias = rel_import .module_alias ,
25182526 )
25192527 type_ident = ident (gt .name )
2520- self .write (f"{ type_ident } = { imported_name } " )
2528+
2529+ if gt in COLLECTION_TYPES :
2530+ # Import collection classes directly so mypy sees them as
2531+ # generic classes, not type aliases
2532+ self .write (
2533+ f"from { rel_import .module } "
2534+ f"import { type_ident } as { type_ident } "
2535+ )
2536+ else :
2537+ self .write (f"{ type_ident } = { imported_name } " )
2538+
25212539 self .export (type_ident )
25222540
25232541 def _write_enum_scalar_type (
0 commit comments