Skip to content

Commit cdd6ed9

Browse files
add plum-dispatch to dev-deps and add test to xtras
1 parent c900bf5 commit cdd6ed9

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

fastcore/_modidx.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,6 @@
578578
'fastcore.xtras._ceil': ('xtras.html#_ceil', 'fastcore/xtras.py'),
579579
'fastcore.xtras._has_property_getter': ('xtras.html#_has_property_getter', 'fastcore/xtras.py'),
580580
'fastcore.xtras._is_property': ('xtras.html#_is_property', 'fastcore/xtras.py'),
581-
'fastcore.xtras._is_type_dispatch': ('xtras.html#_is_type_dispatch', 'fastcore/xtras.py'),
582581
'fastcore.xtras._property_getter': ('xtras.html#_property_getter', 'fastcore/xtras.py'),
583582
'fastcore.xtras._repr_dict': ('xtras.html#_repr_dict', 'fastcore/xtras.py'),
584583
'fastcore.xtras._sparkchar': ('xtras.html#_sparkchar', 'fastcore/xtras.py'),

fastcore/xtras.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,11 @@ def exec_eval(code, # Code to exec/eval
429429
else: exec(code, g, l)
430430

431431
# %% ../nbs/03_xtras.ipynb
432-
def _is_type_dispatch(x): return type(x).__name__ == "Function" # assumes plum-dispatch library is used
433-
def _unwrapped_type_dispatch_func(x): return x.methods[0].implementation if _is_type_dispatch(x) else x
432+
def _unwrapped_type_dispatch_func(x):
433+
# use isinstance_str to avoid adding plum-dispatch as dependency to fastcore
434+
return x.methods[0].implementation if isinstance_str(x,"Function") else x
434435

436+
# %% ../nbs/03_xtras.ipynb
435437
def _is_property(x): return type(x)==property
436438
def _has_property_getter(x): return _is_property(x) and hasattr(x, 'fget') and hasattr(x.fget, 'func')
437439
def _property_getter(x): return x.fget.func if _has_property_getter(x) else x

nbs/03_xtras.ipynb

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,9 +1896,41 @@
18961896
"outputs": [],
18971897
"source": [
18981898
"#|export\n",
1899-
"def _is_type_dispatch(x): return type(x).__name__ == \"Function\" # assumes plum-dispatch library is used\n",
1900-
"def _unwrapped_type_dispatch_func(x): return x.methods[0].implementation if _is_type_dispatch(x) else x\n",
1899+
"def _unwrapped_type_dispatch_func(x): \n",
1900+
" # use isinstance_str to avoid adding plum-dispatch as dependency to fastcore\n",
1901+
" return x.methods[0].implementation if isinstance_str(x,\"Function\") else x"
1902+
]
1903+
},
1904+
{
1905+
"cell_type": "markdown",
1906+
"metadata": {},
1907+
"source": [
1908+
"This function helps us identify the first declared raw function of a dispatched function:"
1909+
]
1910+
},
1911+
{
1912+
"cell_type": "code",
1913+
"execution_count": null,
1914+
"metadata": {},
1915+
"outputs": [],
1916+
"source": [
1917+
"from plum import Function\n",
1918+
"\n",
1919+
"def f1(x): return \"Any\"\n",
1920+
"def f2(x:int): return \"Int\"\n",
1921+
"\n",
1922+
"df = Function(f1).dispatch(f1).dispatch(f2)\n",
19011923
"\n",
1924+
"test_eq(_unwrapped_type_dispatch_func(df), f1)"
1925+
]
1926+
},
1927+
{
1928+
"cell_type": "code",
1929+
"execution_count": null,
1930+
"metadata": {},
1931+
"outputs": [],
1932+
"source": [
1933+
"#|export\n",
19021934
"def _is_property(x): return type(x)==property\n",
19031935
"def _has_property_getter(x): return _is_property(x) and hasattr(x, 'fget') and hasattr(x.fget, 'func')\n",
19041936
"def _property_getter(x): return x.fget.func if _has_property_getter(x) else x\n",

settings.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ license = apache2
1717
status = 5
1818
nbs_path = nbs
1919
doc_path = _docs
20-
dev_requirements = numpy nbdev>=0.2.39 matplotlib pillow torch pandas nbclassic pysymbol_llm llms-txt
20+
dev_requirements = numpy nbdev>=0.2.39 matplotlib pillow torch pandas nbclassic pysymbol_llm llms-txt plum-dispatch
2121
git_url = https://github.com/AnswerDotAI/fastcore/
2222
lib_path = fastcore
2323
title = fastcore
@@ -38,4 +38,3 @@ clear_all = False
3838
put_version_in_init = True
3939
cell_number = False
4040
skip_procs =
41-

0 commit comments

Comments
 (0)