list), 'list')
test_eq(_maybe_nm('fastai'), 'fastai') test_eq(_maybe_nm(
showdoc
Rendering docment Tables
Render nicely formatted tables that shows docments
for any function or method.
DocmentTbl
DocmentTbl (obj, verbose=True, returns=True)
Compute the docment table string
DocmentTbl can render a markdown table showing docments
if appropriate. This is an example of how a docments
table will render for a function:
def _f(a, # description of param a
=True, # description of param b
bstr=None
c:-> int: ...
)
= DocmentTbl(_f)
_dm _dm
Type | Default | Details | |
---|---|---|---|
a | description of param a | ||
b | bool | True | description of param b |
c | str | None | |
Returns | int |
If one column in the table has no information, for example because there are no default values, that column will not be shown. In the below example, the Default column, will not be shown. Additionally, if the return of the function is not annotated the Returns row will not be rendered:
def _f(a,
#param b
b, #param c
c
): ...
= DocmentTbl(_f)
_dm2 _dm2
Details | |
---|---|
a | |
b | param b |
c | param c |
DocmentTbl also works on classes. By default, the __init__
will be rendered:
class _Test:
def __init__(self,
# description of param a
a, =True, # description of param b
bstr=None):
c:
...
def foo(self,
int, # description of param c
c:=True, # description of param d
d
): ...
DocmentTbl(_Test)
Type | Default | Details | |
---|---|---|---|
a | description of param a | ||
b | bool | True | description of param b |
c | str | None |
You can also pass a method to be rendered as well:
DocmentTbl(_Test.foo)
Type | Default | Details | |
---|---|---|---|
c | int | description of param c | |
d | bool | True | description of param d |
Show Complete Documentation For An Object
Render the signature as well as the docments
to show complete documentation for an object.
ShowDocRenderer
ShowDocRenderer (sym, disp:bool=True)
Show documentation for sym
BasicMarkdownRenderer
BasicMarkdownRenderer (sym, disp:bool=True)
Show documentation for sym
show_doc
show_doc (sym, disp=True, renderer=None)
You can use show_doc to document apis of functions, classes or methods:
f
f (x:int=1)
func docstring
f
f (x:int=1)
func docstring
Type | Default | Details | |
---|---|---|---|
x | int | 1 | the parameter x |
Returns | None | this function doesn’t return anything |
Numpy Docstrings
if you have numpy docstrings instead of docments
, show_doc will attempt to parse and render those just like docments
:
f
f (x=1)
func docstring in the numpy style.
Type | Default | Details | |
---|---|---|---|
x | int | 1 | the parameter x |
Returns | None | this function doesn’t return anything |
show_doc on Classes
show_doc works on Classes, too including when you use @patch
:
Foo
Foo (d:str, e:int)
This is the docstring for the init method
You can define methods for the class Foo
with @patch
which is convenient in allowing you to break up code for documentation in notebooks:
@patch
def a_method(self:Foo,
list, # param a
a:dict,c):
b:"This is a method"
...
= show_doc(Foo.a_method)
_res _res
Foo.a_method
Foo.a_method (a:list, b:dict, c)
This is a method
Type | Details | |
---|---|---|
a | list | param a |
b | dict | |
c |
Class properties also work with showdoc:
= show_doc(Foo.some_prop)
_res _res
Foo.some_prop
This is a class property.
BasicHtmlRenderer
BasicHtmlRenderer (sym, disp:bool=True)
Show documentation for sym
F
F(x: int = 1)
class docstring
= show_doc(F.class_method)
_res _res
F.class_method
F.class_method (foo:str, bar:int)
This is a class method.
Type | Details | |
---|---|---|
foo | str | docment for parameter foo |
bar | int |
F.regular_method
F.regular_method (baz:bool=True)
This is a regular method
Type | Default | Details | |
---|---|---|---|
baz | bool | True | docment for parameter baz |
showdoc_nm
showdoc_nm (tree)
Get the fully qualified name for showdoc.