Skip to content

Commit 2582a6e

Browse files
committed
fixes #558
1 parent 9f72b7d commit 2582a6e

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

fastcore/basics.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
# %% ../nbs/01_basics.ipynb 1
2222
from .imports import *
23-
import builtins,types
23+
import builtins,types,typing
2424
import pprint
2525
try: from types import UnionType
2626
except ImportError: UnionType = None
@@ -975,10 +975,13 @@ def _inner(f):
975975
# `functools.update_wrapper` when passing patched function to `Pipeline`, so we do it manually
976976
for o in functools.WRAPPER_ASSIGNMENTS: setattr(nf, o, getattr(f,o))
977977
nf.__qualname__ = f"{c_.__name__}.{nm}"
978-
if cls_method:
979-
setattr(c_, nm, _clsmethod(nf))
978+
if cls_method: setattr(c_, nm, _clsmethod(nf))
980979
else:
981-
setattr(c_, nm, property(nf) if as_prop else nf)
980+
if as_prop: setattr(c_, nm, property(nf))
981+
else:
982+
onm = '_orig_'+nm
983+
if hasattr(c_, nm) and not hasattr(c_, onm): setattr(c_, onm, getattr(c_, nm))
984+
setattr(c_, nm, nf)
982985
# Avoid clobbering existing functions
983986
return globals().get(nm, builtins.__dict__.get(nm, None))
984987
return _inner

nbs/01_basics.ipynb

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"source": [
1818
"#|export\n",
1919
"from fastcore.imports import *\n",
20-
"import builtins,types\n",
20+
"import builtins,types,typing\n",
2121
"import pprint\n",
2222
"try: from types import UnionType\n",
2323
"except ImportError: UnionType = None"
@@ -4263,7 +4263,7 @@
42634263
"text/markdown": [
42644264
"---\n",
42654265
"\n",
4266-
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L784){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
4266+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L792){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
42674267
"\n",
42684268
"#### fastuple\n",
42694269
"\n",
@@ -4274,7 +4274,7 @@
42744274
"text/plain": [
42754275
"---\n",
42764276
"\n",
4277-
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L784){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
4277+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L792){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
42784278
"\n",
42794279
"#### fastuple\n",
42804280
"\n",
@@ -4348,7 +4348,7 @@
43484348
"text/markdown": [
43494349
"---\n",
43504350
"\n",
4351-
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L803){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
4351+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L811){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
43524352
"\n",
43534353
"##### fastuple.add\n",
43544354
"\n",
@@ -4359,7 +4359,7 @@
43594359
"text/plain": [
43604360
"---\n",
43614361
"\n",
4362-
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L803){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
4362+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L811){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
43634363
"\n",
43644364
"##### fastuple.add\n",
43654365
"\n",
@@ -4398,7 +4398,7 @@
43984398
"text/markdown": [
43994399
"---\n",
44004400
"\n",
4401-
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L799){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
4401+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L807){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
44024402
"\n",
44034403
"##### fastuple.mul\n",
44044404
"\n",
@@ -4409,7 +4409,7 @@
44094409
"text/plain": [
44104410
"---\n",
44114411
"\n",
4412-
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L799){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
4412+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L807){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
44134413
"\n",
44144414
"##### fastuple.mul\n",
44154415
"\n",
@@ -4559,7 +4559,7 @@
45594559
"text/markdown": [
45604560
"---\n",
45614561
"\n",
4562-
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L830){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
4562+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L838){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
45634563
"\n",
45644564
"### bind\n",
45654565
"\n",
@@ -4570,7 +4570,7 @@
45704570
"text/plain": [
45714571
"---\n",
45724572
"\n",
4573-
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L830){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
4573+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L838){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
45744574
"\n",
45754575
"### bind\n",
45764576
"\n",
@@ -5218,10 +5218,13 @@
52185218
" # `functools.update_wrapper` when passing patched function to `Pipeline`, so we do it manually\n",
52195219
" for o in functools.WRAPPER_ASSIGNMENTS: setattr(nf, o, getattr(f,o))\n",
52205220
" nf.__qualname__ = f\"{c_.__name__}.{nm}\"\n",
5221-
" if cls_method:\n",
5222-
" setattr(c_, nm, _clsmethod(nf))\n",
5221+
" if cls_method: setattr(c_, nm, _clsmethod(nf))\n",
52235222
" else:\n",
5224-
" setattr(c_, nm, property(nf) if as_prop else nf)\n",
5223+
" if as_prop: setattr(c_, nm, property(nf))\n",
5224+
" else:\n",
5225+
" onm = '_orig_'+nm\n",
5226+
" if hasattr(c_, nm) and not hasattr(c_, onm): setattr(c_, onm, getattr(c_, nm))\n",
5227+
" setattr(c_, nm, nf)\n",
52255228
" # Avoid clobbering existing functions\n",
52265229
" return globals().get(nm, builtins.__dict__.get(nm, None))\n",
52275230
" return _inner"

0 commit comments

Comments
 (0)