@@ -66,14 +66,14 @@ def __init__(
6666 show_signature_annotations : bool = False ,
6767 display_name : str = "relative" ,
6868 hook_pre = None ,
69- use_interlinks = False ,
69+ render_interlinks = False ,
7070 ):
7171 self .header_level = header_level
7272 self .show_signature = show_signature
7373 self .show_signature_annotations = show_signature_annotations
7474 self .display_name = display_name
7575 self .hook_pre = hook_pre
76- self .use_interlinks = use_interlinks
76+ self .render_interlinks = render_interlinks
7777
7878 self .crnt_header_level = self .header_level
7979
@@ -105,27 +105,34 @@ def _render_table(self, rows, headers):
105105
106106 return table
107107
108- def render_annotation (self , el : "str | expr.Name | expr.Expression | None" ):
109- """Special hook for rendering a type annotation.
108+ # render_annotation method --------------------------------------------------------
110109
110+ @dispatch
111+ def render_annotation (self , el : str ) -> str :
112+ """Special hook for rendering a type annotation.
111113 Parameters
112114 ----------
113115 el:
114116 An object representing a type annotation.
115-
116117 """
118+ return sanitize (el )
117119
118- if isinstance (el , type (None )):
119- return el
120- elif isinstance (el , str ):
121- return sanitize (el )
120+ @dispatch
121+ def render_annotation (self , el : None ) -> str :
122+ return ""
122123
124+ @dispatch
125+ def render_annotation (self , el : expr .Name ) -> str :
123126 # TODO: maybe there is a way to get tabulate to handle this?
124127 # unescaped pipes screw up table formatting
125- if isinstance (el , expr .Name ):
126- return sanitize (el .source )
128+ if self .render_interlinks :
129+ return f"[{ sanitize (el .source )} ](`{ el .full } `)"
130+
131+ return sanitize (el .source )
127132
128- return sanitize (el .full )
133+ @dispatch
134+ def render_annotation (self , el : expr .Expression ) -> str :
135+ return "" .join (map (self .render_annotation , el ))
129136
130137 # signature method --------------------------------------------------------
131138
@@ -148,7 +155,6 @@ def signature(self, el: layout.Doc):
148155 @dispatch
149156 def signature (self , el : dc .Alias , source : Optional [dc .Alias ] = None ):
150157 """Return a string representation of an object's signature."""
151-
152158 return self .signature (el .target , el )
153159
154160 @dispatch
@@ -425,17 +431,19 @@ def render(self, el: dc.Parameter):
425431 glob = ""
426432
427433 annotation = self .render_annotation (el .annotation )
434+ name = sanitize (el .name )
435+
428436 if self .show_signature_annotations :
429437 if annotation and has_default :
430- res = f"{ glob } { el . name } : { el . annotation } = { el .default } "
438+ res = f"{ glob } { name } : { annotation } = { el .default } "
431439 elif annotation :
432- res = f"{ glob } { el . name } : { el . annotation } "
440+ res = f"{ glob } { name } : { annotation } "
433441 elif has_default :
434- res = f"{ glob } { el . name } ={ el .default } "
442+ res = f"{ glob } { name } ={ el .default } "
435443 else :
436- res = f"{ glob } { el . name } "
444+ res = f"{ glob } { name } "
437445
438- return sanitize ( res )
446+ return res
439447
440448 # docstring parts -------------------------------------------------------------
441449
@@ -457,7 +465,6 @@ def render(self, el: ds.DocstringSectionText):
457465 def render (self , el : ds .DocstringSectionParameters ):
458466 rows = list (map (self .render , el .value ))
459467 header = ["Name" , "Type" , "Description" , "Default" ]
460-
461468 return self ._render_table (rows , header )
462469
463470 @dispatch
0 commit comments