@@ -724,19 +724,21 @@ def has_multi_line(e: Element) -> bool:
724
724
return e .get ('multi_line_parameter_list' )
725
725
726
726
self .has_tp_list = False
727
+ self .orphan_tp_list = False
727
728
728
729
for child in node :
729
730
if isinstance (child , addnodes .desc_type_parameter_list ):
730
731
self .has_tp_list = True
731
- # recall that return annotations must follow an argument list,
732
- # so signatures of the form "foo[tp_list] -> retann" will not
733
- # be encountered (if they should, the `domains.python.py_sig_re`
734
- # pattern must be modified accordingly)
735
- arglist = next_sibling (child )
736
- assert isinstance (arglist , addnodes .desc_parameterlist )
737
- # tp_list + arglist: \macro{name}{tp_list}{arglist}{return}
738
732
multi_tp_list = has_multi_line (child )
739
- multi_arglist = has_multi_line (arglist )
733
+ arglist = next_sibling (child )
734
+ if isinstance (arglist , addnodes .desc_parameterlist ):
735
+ # tp_list + arglist: \macro{name}{tp_list}{arglist}{retann}
736
+ multi_arglist = has_multi_line (arglist )
737
+ else :
738
+ # orphan tp_list: \macro{name}{tp_list}{}{retann}
739
+ # see: https://github.com/sphinx-doc/sphinx/issues/12543
740
+ self .orphan_tp_list = True
741
+ multi_arglist = False
740
742
741
743
if multi_tp_list :
742
744
if multi_arglist :
@@ -751,7 +753,7 @@ def has_multi_line(e: Element) -> bool:
751
753
break
752
754
753
755
if isinstance (child , addnodes .desc_parameterlist ):
754
- # arglist only: \macro{name}{arglist}{return }
756
+ # arglist only: \macro{name}{arglist}{retann }
755
757
if has_multi_line (child ):
756
758
self .body .append (CR + r'\pysigwithonelineperarg{' )
757
759
else :
@@ -857,7 +859,13 @@ def _visit_sig_parameter_list(self, node: Element, parameter_group: type[Element
857
859
self .multi_line_parameter_list = node .get ('multi_line_parameter_list' , False )
858
860
859
861
def visit_desc_parameterlist (self , node : Element ) -> None :
860
- if not self .has_tp_list :
862
+ if self .has_tp_list :
863
+ if self .orphan_tp_list :
864
+ # close type parameters list (#2)
865
+ self .body .append ('}{' )
866
+ # empty parameters list argument (#3)
867
+ return
868
+ else :
861
869
# close name argument (#1), open parameters list argument (#2)
862
870
self .body .append ('}{' )
863
871
self ._visit_sig_parameter_list (node , addnodes .desc_parameter )
0 commit comments