Skip to content

Commit cd24949

Browse files
authored
Merge pull request #1507 from AnswerDotAI/use-plum-dispatch
Use plum dispatch
2 parents f53f6a3 + bcd2d64 commit cd24949

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

nbdev/showdoc.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
from .doclinks import *
88
from .config import get_config
99

10-
from fastcore.dispatch import TypeDispatch
1110
from fastcore.docments import *
1211
from fastcore.utils import *
1312

1413
from importlib import import_module
1514
import inspect, sys
1615
from collections import OrderedDict
16+
from plum import Function
1717
from textwrap import fill
1818
from types import FunctionType
1919

@@ -189,7 +189,8 @@ def show_doc(sym, # Symbol to document
189189
elif isinstance(renderer,str):
190190
p,m = renderer.rsplit('.', 1)
191191
renderer = getattr(import_module(p), m)
192-
if isinstance(sym, TypeDispatch): pass
192+
if isinstance(sym, Function): pass
193+
elif isinstance_str(sym, "TypeDispatch"): pass # use _str as TypeDispatch will be removed from fastcore
193194
else:return renderer(sym or show_doc, name=name, title_level=title_level)
194195

195196
# %% ../nbs/api/08_showdoc.ipynb

nbs/api/08_showdoc.ipynb

+7-6
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
"from nbdev.doclinks import *\n",
3333
"from nbdev.config import get_config\n",
3434
"\n",
35-
"from fastcore.dispatch import TypeDispatch\n",
3635
"from fastcore.docments import *\n",
3736
"from fastcore.utils import *\n",
3837
"\n",
3938
"from importlib import import_module\n",
4039
"import inspect, sys\n",
4140
"from collections import OrderedDict\n",
41+
"from plum import Function\n",
4242
"from textwrap import fill\n",
4343
"from types import FunctionType"
4444
]
@@ -648,7 +648,8 @@
648648
" elif isinstance(renderer,str):\n",
649649
" p,m = renderer.rsplit('.', 1)\n",
650650
" renderer = getattr(import_module(p), m)\n",
651-
" if isinstance(sym, TypeDispatch): pass\n",
651+
" if isinstance(sym, Function): pass\n",
652+
" elif isinstance_str(sym, \"TypeDispatch\"): pass # use _str as TypeDispatch will be removed from fastcore\n",
652653
" else:return renderer(sym or show_doc, name=name, title_level=title_level)"
653654
]
654655
},
@@ -1334,7 +1335,7 @@
13341335
"outputs": [],
13351336
"source": [
13361337
"#|hide\n",
1337-
"from fastcore.dispatch import typedispatch"
1338+
"from plum import dispatch"
13381339
]
13391340
},
13401341
{
@@ -1345,23 +1346,23 @@
13451346
"outputs": [],
13461347
"source": [
13471348
"#|hide\n",
1348-
"@typedispatch\n",
1349+
"@dispatch\n",
13491350
"def _typ_test(\n",
13501351
" a:list, # A list\n",
13511352
" b:str, # A second integer\n",
13521353
") -> float:\n",
13531354
" \"Perform op\"\n",
13541355
" return a.extend(b)\n",
13551356
"\n",
1356-
"@typedispatch\n",
1357+
"@dispatch\n",
13571358
"def _typ_test(\n",
13581359
" a:str, # An integer\n",
13591360
" b:str # A str\n",
13601361
") -> float:\n",
13611362
" \"Perform op\"\n",
13621363
" return str(a) + b\n",
13631364
"\n",
1364-
"test_eq(show_doc(_typ_test), None) # show_doc ignores typedispatch at the moment"
1365+
"test_eq(show_doc(_typ_test), None) # show_doc ignores dispatch at the moment"
13651366
]
13661367
},
13671368
{

settings.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ language = English
1515
custom_sidebar = True
1616
license = apache2
1717
status = 5
18-
requirements = fastcore>=1.5.27 execnb>=0.1.12 astunparse ghapi>=1.0.3 watchdog asttokens setuptools
18+
requirements = fastcore>=1.5.27 execnb>=0.1.12 astunparse ghapi>=1.0.3 watchdog asttokens setuptools plum-dispatch
1919
pip_requirements = PyYAML
2020
conda_requirements = pyyaml
2121
conda_user = fastai

0 commit comments

Comments
 (0)