@@ -66,14 +66,14 @@ def __init__(
66
66
show_signature_annotations : bool = False ,
67
67
display_name : str = "relative" ,
68
68
hook_pre = None ,
69
- use_interlinks = False ,
69
+ render_interlinks = False ,
70
70
):
71
71
self .header_level = header_level
72
72
self .show_signature = show_signature
73
73
self .show_signature_annotations = show_signature_annotations
74
74
self .display_name = display_name
75
75
self .hook_pre = hook_pre
76
- self .use_interlinks = use_interlinks
76
+ self .render_interlinks = render_interlinks
77
77
78
78
self .crnt_header_level = self .header_level
79
79
@@ -105,27 +105,34 @@ def _render_table(self, rows, headers):
105
105
106
106
return table
107
107
108
- def render_annotation (self , el : "str | expr.Name | expr.Expression | None" ):
109
- """Special hook for rendering a type annotation.
108
+ # render_annotation method --------------------------------------------------------
110
109
110
+ @dispatch
111
+ def render_annotation (self , el : str ) -> str :
112
+ """Special hook for rendering a type annotation.
111
113
Parameters
112
114
----------
113
115
el:
114
116
An object representing a type annotation.
115
-
116
117
"""
118
+ return sanitize (el )
117
119
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 ""
122
123
124
+ @dispatch
125
+ def render_annotation (self , el : expr .Name ) -> str :
123
126
# TODO: maybe there is a way to get tabulate to handle this?
124
127
# 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 )
127
132
128
- return sanitize (el .full )
133
+ @dispatch
134
+ def render_annotation (self , el : expr .Expression ) -> str :
135
+ return "" .join (map (self .render_annotation , el ))
129
136
130
137
# signature method --------------------------------------------------------
131
138
@@ -148,7 +155,6 @@ def signature(self, el: layout.Doc):
148
155
@dispatch
149
156
def signature (self , el : dc .Alias , source : Optional [dc .Alias ] = None ):
150
157
"""Return a string representation of an object's signature."""
151
-
152
158
return self .signature (el .target , el )
153
159
154
160
@dispatch
@@ -425,17 +431,19 @@ def render(self, el: dc.Parameter):
425
431
glob = ""
426
432
427
433
annotation = self .render_annotation (el .annotation )
434
+ name = sanitize (el .name )
435
+
428
436
if self .show_signature_annotations :
429
437
if annotation and has_default :
430
- res = f"{ glob } { el . name } : { el . annotation } = { el .default } "
438
+ res = f"{ glob } { name } : { annotation } = { el .default } "
431
439
elif annotation :
432
- res = f"{ glob } { el . name } : { el . annotation } "
440
+ res = f"{ glob } { name } : { annotation } "
433
441
elif has_default :
434
- res = f"{ glob } { el . name } ={ el .default } "
442
+ res = f"{ glob } { name } ={ el .default } "
435
443
else :
436
- res = f"{ glob } { el . name } "
444
+ res = f"{ glob } { name } "
437
445
438
- return sanitize ( res )
446
+ return res
439
447
440
448
# docstring parts -------------------------------------------------------------
441
449
@@ -457,7 +465,6 @@ def render(self, el: ds.DocstringSectionText):
457
465
def render (self , el : ds .DocstringSectionParameters ):
458
466
rows = list (map (self .render , el .value ))
459
467
header = ["Name" , "Type" , "Description" , "Default" ]
460
-
461
468
return self ._render_table (rows , header )
462
469
463
470
@dispatch
0 commit comments