36
36
Return ,
37
37
TopLevel ,
38
38
Type ,
39
+ TypeAlias ,
39
40
TypeParam ,
40
41
TypeXRef ,
41
42
TypeXRefInternal ,
@@ -337,7 +338,7 @@ def rst_nodes(self) -> list[Node]:
337
338
def rst_for (self , obj : TopLevel ) -> str :
338
339
renderer_class : type
339
340
match obj :
340
- case Attribute (_):
341
+ case Attribute (_) | TypeAlias (_) :
341
342
renderer_class = AutoAttributeRenderer
342
343
case Function (_):
343
344
renderer_class = AutoFunctionRenderer
@@ -374,7 +375,7 @@ def rst(
374
375
result = "\n " .join (lines ) + "\n "
375
376
return result
376
377
377
- def _type_params (self , obj : Function | Class | Interface ) -> str :
378
+ def _type_params (self , obj : Function | Class | TypeAlias | Interface ) -> str :
378
379
if not obj .type_params :
379
380
return ""
380
381
return "<{}>" .format (", " .join (tp .name for tp in obj .type_params ))
@@ -654,19 +655,34 @@ class AutoAttributeRenderer(JsRenderer):
654
655
_template = "attribute.rst"
655
656
_renderer_type = "attribute"
656
657
657
- def _template_vars (self , name : str , obj : Attribute ) -> dict [str , Any ]: # type: ignore[override]
658
+ def _template_vars (self , name : str , obj : Attribute | TypeAlias ) -> dict [str , Any ]: # type: ignore[override]
659
+ is_optional = False
660
+ if isinstance (obj , Attribute ):
661
+ is_optional = obj .is_optional
662
+ type_params = ""
663
+ is_type_alias = isinstance (obj , TypeAlias )
664
+ fields : Iterator [tuple [list [str ], str ]] = iter ([])
665
+ if isinstance (obj , TypeAlias ):
666
+ type_params = self ._type_params (obj )
667
+ fields = self ._fields (obj )
658
668
return dict (
659
669
name = name ,
670
+ is_type_alias = is_type_alias ,
671
+ type_params = type_params ,
672
+ fields = fields ,
660
673
description = render_description (obj .description ),
661
674
deprecated = obj .deprecated ,
662
- is_optional = obj . is_optional ,
675
+ is_optional = is_optional ,
663
676
see_also = obj .see_alsos ,
664
677
examples = [render_description (ex ) for ex in obj .examples ],
665
678
type = self .render_type (obj .type ),
666
679
content = "\n " .join (self ._content ),
667
680
)
668
681
669
682
683
+ _SECTION_ORDER = ["type_aliases" , "attributes" , "functions" , "interfaces" , "classes" ]
684
+
685
+
670
686
class AutoModuleRenderer (JsRenderer ):
671
687
def _parse_path (self , arg : str ) -> None :
672
688
# content, arguments, options, app: all need to be accessible to
@@ -692,10 +708,8 @@ def rst( # type:ignore[override]
692
708
) -> str :
693
709
rst : list [Sequence [str ]] = []
694
710
rst .append ([f".. js:module:: { '' .join (partial_path )} " ])
695
- rst .append (self .rst_for_group (obj .attributes ))
696
- rst .append (self .rst_for_group (obj .functions ))
697
- rst .append (self .rst_for_group (obj .classes ))
698
- rst .append (self .rst_for_group (obj .interfaces ))
711
+ for group_name in _SECTION_ORDER :
712
+ rst .append (self .rst_for_group (getattr (obj , group_name )))
699
713
return "\n \n " .join (["\n \n " .join (r ) for r in rst ])
700
714
701
715
@@ -715,20 +729,15 @@ def get_object(self) -> Module:
715
729
716
730
def rst_nodes (self ) -> list [Node ]:
717
731
module = self .get_object ()
718
- pairs : list [tuple [str , Iterable [TopLevel ]]] = [
719
- ("attributes" , module .attributes ),
720
- ("functions" , module .functions ),
721
- ("classes" , module .classes ),
722
- ("interfaces" , module .interfaces ),
723
- ]
724
732
pkgname = "" .join (self ._partial_path )
725
733
726
734
result : list [Node ] = []
727
- for group_name , group_objects in pairs :
728
- n = nodes . container ( )
735
+ for group_name in _SECTION_ORDER :
736
+ group_objects = getattr ( module , group_name )
729
737
if not group_objects :
730
738
continue
731
- n += self .format_heading (group_name .title () + ":" )
739
+ n = nodes .container ()
740
+ n += self .format_heading (group_name .replace ("_" , " " ).title () + ":" )
732
741
table_items = self .get_summary_table (pkgname , group_objects )
733
742
n += self .format_table (table_items )
734
743
n ["classes" ] += ["jssummarytable" , group_name ]
0 commit comments