Testing `%nbdev_show_doc` and showing how it works.
Showing multiple elements with a single %nbdev_show_doc
https://github.com/fastai/fastai2/blob/master/nbs/00_torch_core.ipynb makes a few show_doc
calls which could be written with one %nbdev_show_doc
In the example above ↑
title_level=
can appear anywhere in the list of names- list of things are classes but could be functions etc
- could also be written as a space separated list
%nbdev_show_doc TitledInt TitledStr TitledFloat title_level=3
Not having to pass name=
might be nice
https://github.com/fastai/fastai2/blob/master/nbs/03_data.core.ipynb makes a few show_doc
calls which could be written with one %nbdev_show_doc
without having to pass name=
In the example above ↑
- The
.
tells nbdev_show_doc to show class members - could also be written as a comma separated list
%nbdev_show_doc DataLoaders ., __getitem__, train, valid, train_ds, valid_ds
- or use a mixture of separators
%nbdev_show_doc DataLoaders . __getitem__, train,valid, train_ds valid_ds
In the example above ↑
- The
*
tells nbdev_show_doc to show all public members - in this case, nbdev_show_doc sees everything in
_docs
as a public member- hopefully this is a good shortcut if you use fastcore
@docs
- hopefully this is a good shortcut if you use fastcore
from enum import Enum
class Thing():
"A thing"
def __init__(self):
"initialize a thing"
def do_something(self):
"make the thing do something"
def a(self):
"a does something ..."
@property
def c_thing(self):
"c is a property of Thing"
return 5
_docs=dict(int='This element is not part of Thing',)
class Color(Thing):
"A few colors"
RED=1
GREEN=2
def __init__(self):
"initialize a color"
self.x='should make no difference'
def a(self):
"a does nothing"
def b(self, a):
"b does nothing with `a`"
@property
def c(self):
"c is a property"
return 5
class Hue():
"The hue of a color"
def apply(self):
"Apply this hue"
class Shade(Enum):
"The shade"
DARK=0
LIGHT=1
In the example above ↑
- The
*
tells nbdev_show_doc to show all public members - in this case,
Color
doesn't have_docs
so we use "inspect" logic and list members that:- don't start with single
_
- are defined by the element being inspected
- are either executable or are properties
- don't start with single
In the example below ↓
Thing
does have_docs
but it's not valid- so we fall back to the "inspect" logic
from fastai2.imports import *
class A:
"a class"
class NestedA:
"a nested class"
class B():
"b class"
def c():
"c func"
d="d is an object def"
@patch
def e(x:A.NestedA):
"patch e onto A.NestedA"
is it a problem that
%nbdev_show_doc
->A.NestedA.e
(this one gets doc linked)show_doc
->NestedA.e