@@ -310,7 +310,8 @@ class _ApiEntityMemberReference(NamedTuple):
310
310
name : str
311
311
canonical_object_name : str
312
312
parent_canonical_object_name : str
313
- inherited : bool = False
313
+ inherited : bool
314
+ siblings : List ["_ApiEntityMemberReference" ]
314
315
315
316
316
317
@dataclasses .dataclass
@@ -357,8 +358,10 @@ def overload_suffix(self) -> str:
357
358
base_classes : Optional [List [str ]] = None
358
359
"""List of base classes, as rST cross references."""
359
360
360
- siblings : Optional [List [_ApiEntityMemberReference ]] = None
361
- """List of siblings that should be documented as aliases."""
361
+ siblings : Optional [Dict [str , bool ]] = None
362
+ """List of siblings that should be documented as aliases.
363
+
364
+ The key is the canonical_object_name of the sibling. The value is always `True`."""
362
365
363
366
primary_entity : bool = True
364
367
"""Indicates if this is the primary sibling and should be documented."""
@@ -593,18 +596,24 @@ def object_description_transform(
593
596
content = entity .content
594
597
options = dict (entity .options )
595
598
options ["nonodeid" ] = ""
596
- all_entities_and_members = [
597
- (entity , member ),
598
- * [
599
- (
600
- api_data .entities [sibling_member .canonical_object_name ],
601
- sibling_member if member is not None else None ,
602
- )
603
- for sibling_member in (entity .siblings or [])
604
- ],
605
- ]
599
+ all_members : List [Optional [_ApiEntityMemberReference ]]
600
+ if member is not None :
601
+ all_members = cast (
602
+ List [Optional [_ApiEntityMemberReference ]], [member ] + member .siblings
603
+ )
604
+ all_entities = [
605
+ api_data .entities [cast (_ApiEntityMemberReference , m ).canonical_object_name ]
606
+ for m in all_members
607
+ ]
608
+ else :
609
+ all_entities = [
610
+ entity ,
611
+ * (api_data .entities [s ] for s in (entity .siblings or {})),
612
+ ]
613
+ all_members = [None ] * len (all_entities )
614
+
606
615
options ["object-ids" ] = json .dumps (
607
- [e .object_name for e , _ in all_entities_and_members for _ in e .signatures ]
616
+ [e .object_name for e in all_entities for _ in e .signatures ]
608
617
)
609
618
if summary :
610
619
content = _summarize_rst_content (content )
@@ -627,7 +636,7 @@ def object_description_transform(
627
636
)
628
637
629
638
signatures : List [str ] = []
630
- for e , m in all_entities_and_members :
639
+ for e , m in zip ( all_entities , all_members ) :
631
640
name = api_data .get_name_for_signature (e , m )
632
641
signatures .extend (name + sig for sig in e .signatures )
633
642
@@ -666,7 +675,7 @@ def object_description_transform(
666
675
if not summary :
667
676
py = cast (PythonDomain , env .get_domain ("py" ))
668
677
669
- for e , _ in all_entities_and_members :
678
+ for e in all_entities :
670
679
py .objects .setdefault (
671
680
e .canonical_object_name ,
672
681
py .objects [e .object_name ]._replace (aliased = True ),
@@ -1472,11 +1481,15 @@ def __init__(
1472
1481
def collect_entity_recursively (
1473
1482
self ,
1474
1483
entry : _MemberDocumenterEntry ,
1475
- primary_sibling : Optional [_ApiEntity ] = None ,
1484
+ primary_entity : Optional [_ApiEntity ] = None ,
1476
1485
) -> str :
1477
1486
canonical_full_name = None
1478
1487
if isinstance (entry .documenter , sphinx .ext .autodoc .ClassDocumenter ):
1479
1488
canonical_full_name = entry .documenter .get_canonical_fullname ()
1489
+ elif isinstance (entry .documenter , sphinx .ext .autodoc .FunctionDocumenter ):
1490
+ canonical_full_name = sphinx .ext .autodoc .ClassDocumenter .get_canonical_fullname (
1491
+ entry .documenter # type: ignore[arg-type]
1492
+ )
1480
1493
if canonical_full_name is None :
1481
1494
canonical_full_name = f"{ entry .parent_canonical_full_name } .{ entry .name } "
1482
1495
@@ -1492,7 +1505,7 @@ def collect_entity_recursively(
1492
1505
):
1493
1506
logger .warning ("Unspecified overload id: %s" , canonical_object_name )
1494
1507
1495
- if primary_sibling is None :
1508
+ if primary_entity is None :
1496
1509
rst_strings = docutils .statemachine .StringList ()
1497
1510
entry .documenter .directive .result = rst_strings
1498
1511
_prepare_documenter_docstring (entry )
@@ -1514,11 +1527,11 @@ def document_members(*args, **kwargs):
1514
1527
options = split_result .options
1515
1528
content = split_result .content
1516
1529
else :
1517
- group_name = primary_sibling .group_name
1518
- order = primary_sibling .order
1519
- directive = primary_sibling .directive
1520
- options = primary_sibling .options
1521
- content = primary_sibling .content
1530
+ group_name = primary_entity .group_name
1531
+ order = primary_entity .order
1532
+ directive = primary_entity .directive
1533
+ options = primary_entity .options
1534
+ content = primary_entity .content
1522
1535
1523
1536
base_classes : Optional [List [str ]] = None
1524
1537
@@ -1570,6 +1583,7 @@ def document_members(*args, **kwargs):
1570
1583
subscript = entry .subscript ,
1571
1584
overload_id = overload_id or "" ,
1572
1585
base_classes = base_classes ,
1586
+ primary_entity = primary_entity is None ,
1573
1587
)
1574
1588
1575
1589
self .entities [canonical_object_name ] = entity
@@ -1579,8 +1593,8 @@ def document_members(*args, **kwargs):
1579
1593
entry .documenter ,
1580
1594
canonical_object_name = canonical_object_name ,
1581
1595
)
1582
- if primary_sibling is None
1583
- else primary_sibling .members
1596
+ if primary_entity is None
1597
+ else primary_entity .members
1584
1598
)
1585
1599
1586
1600
return canonical_object_name
@@ -1613,30 +1627,36 @@ def collect_documenter_members(
1613
1627
Tuple [Any , _ApiEntityMemberReference ]
1614
1628
] = None
1615
1629
primary_sibling_entity : Optional [_ApiEntity ] = None
1630
+ primary_sibling_member : Optional [_ApiEntityMemberReference ] = None
1616
1631
if obj is not None :
1617
1632
obj_and_primary_sibling_member = object_to_api_entity_member_map .get (
1618
1633
id (obj )
1619
1634
)
1620
1635
if obj_and_primary_sibling_member is not None :
1636
+ primary_sibling_member = obj_and_primary_sibling_member [1 ]
1621
1637
primary_sibling_entity = self .entities [
1622
- obj_and_primary_sibling_member [ 1 ] .canonical_object_name
1638
+ primary_sibling_member .canonical_object_name
1623
1639
]
1624
1640
member_canonical_object_name = self .collect_entity_recursively (
1625
- entry , primary_sibling = primary_sibling_entity
1641
+ entry , primary_entity = primary_sibling_entity
1626
1642
)
1627
1643
child = self .entities [member_canonical_object_name ]
1628
1644
member = _ApiEntityMemberReference (
1629
1645
name = entry .name ,
1630
1646
parent_canonical_object_name = canonical_object_name ,
1631
1647
canonical_object_name = member_canonical_object_name ,
1632
1648
inherited = entry .is_inherited ,
1649
+ siblings = [],
1633
1650
)
1634
1651
1635
- if primary_sibling_entity is not None :
1636
- child .primary_entity = False
1652
+ if primary_sibling_member is not None :
1653
+ primary_sibling_member .siblings .append (member )
1654
+ assert primary_sibling_entity is not None
1637
1655
if primary_sibling_entity .siblings is None :
1638
- primary_sibling_entity .siblings = []
1639
- primary_sibling_entity .siblings .append (member )
1656
+ primary_sibling_entity .siblings = {}
1657
+ primary_sibling_entity .siblings .setdefault (
1658
+ member_canonical_object_name , True
1659
+ )
1640
1660
else :
1641
1661
if obj is not None :
1642
1662
object_to_api_entity_member_map [id (obj )] = (obj , member )
0 commit comments