2323
2424from gel ._internal import _dataclass_extras
2525from gel ._internal import _edgeql
26- from gel ._internal ._schemapath import SchemaPath
26+ from gel ._internal ._schemapath import ParametricTypeName , TypeName
2727
2828from . import _query
2929from ._base import struct , sobject , SchemaObject
@@ -69,7 +69,7 @@ def __str__(self) -> str:
6969
7070 @functools .cached_property
7171 def edgeql (self ) -> str :
72- return self .schemapath .as_quoted_schema_name ()
72+ return self .type_name .as_quoted_schema_name ()
7373
7474 @functools .cached_property
7575 def generic (self ) -> bool :
@@ -80,6 +80,10 @@ def generic(self) -> bool:
8080 and sp .name .startswith ("any" )
8181 )
8282
83+ @functools .cached_property
84+ def type_name (self ) -> TypeName :
85+ return self .schemapath
86+
8387 def assignable_from (
8488 self ,
8589 other : Type ,
@@ -182,10 +186,6 @@ class InheritingType(Type):
182186 bases : tuple [TypeRef , ...]
183187 ancestors : tuple [TypeRef , ...]
184188
185- @functools .cached_property
186- def edgeql (self ) -> str :
187- return self .schemapath .as_quoted_schema_name ()
188-
189189 def _assignable_from (
190190 self ,
191191 other : Type ,
@@ -330,11 +330,7 @@ def __post_init__(self) -> None:
330330
331331 @functools .cached_property
332332 def edgeql (self ) -> str :
333- return str (self .schemapath )
334-
335- @functools .cached_property
336- def schemapath (self ) -> SchemaPath :
337- return SchemaPath .from_segments (self .name )
333+ return str (self .type_name )
338334
339335
340336@struct
@@ -361,6 +357,15 @@ def get_element_type(self, schema: Schema) -> Type:
361357 else :
362358 return schema [self ._element_type_id ]
363359
360+ @functools .cached_property
361+ def type_name (self ) -> TypeName :
362+ if self .element_type is None :
363+ return self .schemapath
364+ else :
365+ return ParametricTypeName (
366+ self .schemapath , [self .element_type .type_name ]
367+ )
368+
364369 @functools .cached_property
365370 def _element_type_id (self ) -> str :
366371 raise NotImplementedError ("_element_type_id" )
@@ -457,6 +462,19 @@ def get_element_types(self, schema: Schema) -> tuple[Type, ...]:
457462 else :
458463 return tuple (schema [el_tid ] for el_tid in self ._element_type_ids )
459464
465+ @functools .cached_property
466+ def type_name (self ) -> TypeName :
467+ if self .element_types is None :
468+ return self .schemapath
469+ else :
470+ return ParametricTypeName (
471+ self .schemapath ,
472+ [
473+ element_type .type_name
474+ for element_type in self .element_types
475+ ],
476+ )
477+
460478 @functools .cached_property
461479 def _element_type_ids (self ) -> list [str ]:
462480 raise NotImplementedError ("_element_type_ids" )
@@ -573,8 +591,8 @@ def _element_type_id(self) -> str:
573591 return self .array_element_id
574592
575593 def get_id_and_name (self , element_type : Type ) -> tuple [str , str ]:
576- id_ , name = _edgeql .get_array_type_id_and_name (element_type .name )
577- return str (id_ ), name . as_schema_name ()
594+ id_ , _ = _edgeql .get_array_type_id_and_name (element_type .type_name )
595+ return str (id_ ), "std::array"
578596
579597
580598@struct
@@ -599,8 +617,8 @@ def _element_type_id(self) -> str:
599617 return self .range_element_id
600618
601619 def get_id_and_name (self , element_type : Type ) -> tuple [str , str ]:
602- id_ , name = _edgeql .get_range_type_id_and_name (element_type .name )
603- return str (id_ ), name . as_schema_name ()
620+ id_ , _ = _edgeql .get_range_type_id_and_name (element_type .type_name )
621+ return str (id_ ), "std::range"
604622
605623
606624@struct
@@ -625,8 +643,10 @@ def _element_type_id(self) -> str:
625643 return self .multirange_element_id
626644
627645 def get_id_and_name (self , element_type : Type ) -> tuple [str , str ]:
628- id_ , name = _edgeql .get_multirange_type_id_and_name (element_type .name )
629- return str (id_ ), name .as_schema_name ()
646+ id_ , _ = _edgeql .get_multirange_type_id_and_name (
647+ element_type .type_name
648+ )
649+ return str (id_ ), "std::multirange"
630650
631651
632652@struct
@@ -662,10 +682,10 @@ def kind(self) -> Literal[TypeKind.Tuple]:
662682 def get_id_and_name (
663683 self , element_types : tuple [Type , ...]
664684 ) -> tuple [str , str ]:
665- id_ , name = _edgeql .get_tuple_type_id_and_name (
666- el .name for el in element_types
685+ id_ , _ = _edgeql .get_tuple_type_id_and_name (
686+ [ el .type_name for el in element_types ]
667687 )
668- return str (id_ ), name . as_schema_name ()
688+ return str (id_ ), "std::tuple"
669689
670690
671691@struct
@@ -686,15 +706,15 @@ def kind(self) -> Literal[TypeKind.NamedTuple]:
686706 def get_id_and_name (
687707 self , element_types : tuple [Type , ...]
688708 ) -> tuple [str , str ]:
689- id_ , name = _edgeql .get_named_tuple_type_id_and_name (
709+ id_ , _ = _edgeql .get_named_tuple_type_id_and_name (
690710 {
691- el .name : el_type .name
711+ el .name : el_type .type_name
692712 for el , el_type in zip (
693713 self .tuple_elements , element_types , strict = True
694714 )
695715 }
696716 )
697- return str (id_ ), name . as_schema_name ()
717+ return str (id_ ), "std::tuple"
698718
699719
700720def compare_type_generality (a : Type , b : Type , * , schema : Schema ) -> int :
0 commit comments