Skip to content

Use plum for type dispatch #1503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nbdev/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.3.35"
__version__ = "2.3.36"

from .doclinks import nbdev_export
from .showdoc import show_doc
Expand Down
4 changes: 2 additions & 2 deletions nbdev/showdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from .doclinks import *
from .config import get_config

from fastcore.dispatch import TypeDispatch
from fastcore.docments import *
from fastcore.utils import *

from importlib import import_module
import inspect, sys
from collections import OrderedDict
from plum import Function
from textwrap import fill
from types import FunctionType

Expand Down Expand Up @@ -189,7 +189,7 @@ def show_doc(sym, # Symbol to document
elif isinstance(renderer,str):
p,m = renderer.rsplit('.', 1)
renderer = getattr(import_module(p), m)
if isinstance(sym, TypeDispatch): pass
if isinstance(sym, Function): pass
else:return renderer(sym or show_doc, name=name, title_level=title_level)

# %% ../nbs/api/08_showdoc.ipynb
Expand Down
12 changes: 6 additions & 6 deletions nbs/api/08_showdoc.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
"from nbdev.doclinks import *\n",
"from nbdev.config import get_config\n",
"\n",
"from fastcore.dispatch import TypeDispatch\n",
"from fastcore.docments import *\n",
"from fastcore.utils import *\n",
"\n",
"from importlib import import_module\n",
"import inspect, sys\n",
"from collections import OrderedDict\n",
"from plum import Function\n",
"from textwrap import fill\n",
"from types import FunctionType"
]
Expand Down Expand Up @@ -648,7 +648,7 @@
" elif isinstance(renderer,str):\n",
" p,m = renderer.rsplit('.', 1)\n",
" renderer = getattr(import_module(p), m)\n",
" if isinstance(sym, TypeDispatch): pass\n",
" if isinstance(sym, Function): pass\n",
" else:return renderer(sym or show_doc, name=name, title_level=title_level)"
]
},
Expand Down Expand Up @@ -1334,7 +1334,7 @@
"outputs": [],
"source": [
"#|hide\n",
"from fastcore.dispatch import typedispatch"
"from plum import dispatch"
]
},
{
Expand All @@ -1345,23 +1345,23 @@
"outputs": [],
"source": [
"#|hide\n",
"@typedispatch\n",
"@dispatch\n",
"def _typ_test(\n",
" a:list, # A list\n",
" b:str, # A second integer\n",
") -> float:\n",
" \"Perform op\"\n",
" return a.extend(b)\n",
"\n",
"@typedispatch\n",
"@dispatch\n",
"def _typ_test(\n",
" a:str, # An integer\n",
" b:str # A str\n",
") -> float:\n",
" \"Perform op\"\n",
" return str(a) + b\n",
"\n",
"test_eq(show_doc(_typ_test), None) # show_doc ignores typedispatch at the moment"
"test_eq(show_doc(_typ_test), None) # show_doc ignores dispatch at the moment"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ author = Jeremy Howard and Hamel Husain
author_email = [email protected]
branch = master
min_python = 3.7
version = 2.3.35
version = 2.3.36
audience = Developers
language = English
custom_sidebar = True
license = apache2
status = 5
requirements = fastcore>=1.5.27 execnb>=0.1.4 astunparse ghapi>=1.0.3 watchdog asttokens setuptools
requirements = fastcore>=1.5.27 execnb>=0.1.12 astunparse ghapi>=1.0.3 watchdog asttokens setuptools plum-dispatch
pip_requirements = PyYAML
conda_requirements = pyyaml
conda_user = fastai
Expand Down