Skip to content

Commit 7b1eaea

Browse files
committed
fixes #578
1 parent c2ec565 commit 7b1eaea

File tree

4 files changed

+127
-49
lines changed

4 files changed

+127
-49
lines changed

fastcore/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.5.49"
1+
__version__ = "1.5.50"

fastcore/xtras.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -653,23 +653,27 @@ def nullable_dc(cls):
653653
return dataclass(cls)
654654

655655
# %% ../nbs/03_xtras.ipynb 173
656-
def make_nullable(cls):
656+
def make_nullable(clas):
657657
from dataclasses import dataclass, fields, MISSING
658-
if hasattr(cls, '_nullable'): return
659-
cls._nullable = True
658+
if hasattr(clas, '_nullable'): return
659+
clas._nullable = True
660660

661-
@patch
662-
def __init__(self:cls, *args, **kwargs):
663-
flds = fields(cls)
661+
original_init = clas.__init__
662+
def __init__(self, *args, **kwargs):
663+
flds = fields(clas)
664664
dargs = {k.name:v for k,v in zip(flds, args)}
665665
for f in flds:
666666
nm = f.name
667667
if nm not in dargs and nm not in kwargs and f.default is None and f.default_factory is MISSING:
668668
kwargs[nm] = None
669-
self._orig___init__(*args, **kwargs)
669+
original_init(self, *args, **kwargs)
670670

671-
for f in fields(cls):
671+
clas.__init__ = __init__
672+
673+
for f in fields(clas):
672674
if f.default is MISSING and f.default_factory is MISSING: f.default = None
675+
676+
return clas
673677

674678
# %% ../nbs/03_xtras.ipynb 177
675679
def mk_dataclass(cls):

nbs/03_xtras.ipynb

Lines changed: 113 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@
11881188
{
11891189
"data": {
11901190
"text/plain": [
1191-
"Path('/home/lgvaz/git/fastcore/fastcore')"
1191+
"Path('/Users/jhoward/Documents/GitHub/fastcore/fastcore')"
11921192
]
11931193
},
11941194
"execution_count": null,
@@ -1255,7 +1255,7 @@
12551255
{
12561256
"data": {
12571257
"text/plain": [
1258-
"Path('05_transform.ipynb')"
1258+
"Path('000_tour.ipynb')"
12591259
]
12601260
},
12611261
"execution_count": null,
@@ -1289,7 +1289,7 @@
12891289
{
12901290
"data": {
12911291
"text/plain": [
1292-
"(Path('../fastcore/all.py'), Path('05_transform.ipynb'))"
1292+
"(Path('../fastcore/shutil.py'), Path('000_tour.ipynb'))"
12931293
]
12941294
},
12951295
"execution_count": null,
@@ -1434,14 +1434,24 @@
14341434
"text/markdown": [
14351435
"---\n",
14361436
"\n",
1437-
"### ReindexCollection\n",
1437+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L380){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
14381438
"\n",
1439-
"> ReindexCollection (coll, idxs=None, cache=None, tfm=<functionnoop>)\n",
1439+
"#### ReindexCollection\n",
14401440
"\n",
1441-
"Reindexes collection `coll` with indices `idxs` and optional LRU cache of size `cache`"
1441+
"> ReindexCollection (coll, idxs=None, cache=None, tfm=<function noop>)\n",
1442+
"\n",
1443+
"*Reindexes collection `coll` with indices `idxs` and optional LRU cache of size `cache`*"
14421444
],
14431445
"text/plain": [
1444-
"<nbdev.showdoc.BasicMarkdownRenderer>"
1446+
"---\n",
1447+
"\n",
1448+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L380){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
1449+
"\n",
1450+
"#### ReindexCollection\n",
1451+
"\n",
1452+
"> ReindexCollection (coll, idxs=None, cache=None, tfm=<function noop>)\n",
1453+
"\n",
1454+
"*Reindexes collection `coll` with indices `idxs` and optional LRU cache of size `cache`*"
14451455
]
14461456
},
14471457
"execution_count": null,
@@ -1507,14 +1517,24 @@
15071517
"text/markdown": [
15081518
"---\n",
15091519
"\n",
1510-
"#### ReindexCollection.reindex\n",
1520+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L391){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
1521+
"\n",
1522+
"###### ReindexCollection.reindex\n",
15111523
"\n",
15121524
"> ReindexCollection.reindex (idxs)\n",
15131525
"\n",
1514-
"Replace `self.idxs` with idxs"
1526+
"*Replace `self.idxs` with idxs*"
15151527
],
15161528
"text/plain": [
1517-
"<nbdev.showdoc.BasicMarkdownRenderer>"
1529+
"---\n",
1530+
"\n",
1531+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L391){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
1532+
"\n",
1533+
"###### ReindexCollection.reindex\n",
1534+
"\n",
1535+
"> ReindexCollection.reindex (idxs)\n",
1536+
"\n",
1537+
"*Replace `self.idxs` with idxs*"
15181538
]
15191539
},
15201540
"execution_count": null,
@@ -1597,14 +1617,24 @@
15971617
"text/markdown": [
15981618
"---\n",
15991619
"\n",
1600-
"#### ReindexCollection.cache_clear\n",
1620+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L395){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
1621+
"\n",
1622+
"##### ReindexCollection.cache_clear\n",
16011623
"\n",
16021624
"> ReindexCollection.cache_clear ()\n",
16031625
"\n",
1604-
"Clear LRU cache"
1626+
"*Clear LRU cache*"
16051627
],
16061628
"text/plain": [
1607-
"<nbdev.showdoc.BasicMarkdownRenderer>"
1629+
"---\n",
1630+
"\n",
1631+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L395){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
1632+
"\n",
1633+
"##### ReindexCollection.cache_clear\n",
1634+
"\n",
1635+
"> ReindexCollection.cache_clear ()\n",
1636+
"\n",
1637+
"*Clear LRU cache*"
16081638
]
16091639
},
16101640
"execution_count": null,
@@ -1652,14 +1682,24 @@
16521682
"text/markdown": [
16531683
"---\n",
16541684
"\n",
1655-
"#### ReindexCollection.shuffle\n",
1685+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L392){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
1686+
"\n",
1687+
"##### ReindexCollection.shuffle\n",
16561688
"\n",
16571689
"> ReindexCollection.shuffle ()\n",
16581690
"\n",
1659-
"Randomly shuffle indices"
1691+
"*Randomly shuffle indices*"
16601692
],
16611693
"text/plain": [
1662-
"<nbdev.showdoc.BasicMarkdownRenderer>"
1694+
"---\n",
1695+
"\n",
1696+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L392){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
1697+
"\n",
1698+
"##### ReindexCollection.shuffle\n",
1699+
"\n",
1700+
"> ReindexCollection.shuffle ()\n",
1701+
"\n",
1702+
"*Randomly shuffle indices*"
16631703
]
16641704
},
16651705
"execution_count": null,
@@ -1686,7 +1726,7 @@
16861726
{
16871727
"data": {
16881728
"text/plain": [
1689-
"['d', 'f', 'g', 'a', 'h', 'e', 'b', 'c']"
1729+
"['h', 'g', 'a', 'd', 'b', 'e', 'f', 'c']"
16901730
]
16911731
},
16921732
"execution_count": null,
@@ -2102,14 +2142,24 @@
21022142
"text/markdown": [
21032143
"---\n",
21042144
"\n",
2105-
"### EventTimer\n",
2145+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L502){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
2146+
"\n",
2147+
"#### EventTimer\n",
21062148
"\n",
21072149
"> EventTimer (store=5, span=60)\n",
21082150
"\n",
2109-
"An event timer with history of `store` items of time `span`"
2151+
"*An event timer with history of `store` items of time `span`*"
21102152
],
21112153
"text/plain": [
2112-
"<nbdev.showdoc.BasicMarkdownRenderer>"
2154+
"---\n",
2155+
"\n",
2156+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L502){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
2157+
"\n",
2158+
"#### EventTimer\n",
2159+
"\n",
2160+
"> EventTimer (store=5, span=60)\n",
2161+
"\n",
2162+
"*An event timer with history of `store` items of time `span`*"
21132163
]
21142164
},
21152165
"execution_count": null,
@@ -2137,8 +2187,8 @@
21372187
"name": "stdout",
21382188
"output_type": "stream",
21392189
"text": [
2140-
"Num Events: 3, Freq/sec: 242.1\n",
2141-
"Most recent: ▇▁▂▃▁ 358.8 267.5 296.5 315.5 266.4\n"
2190+
"Num Events: 3, Freq/sec: 256.2\n",
2191+
"Most recent: ▁▃▇▅▂ 223.9 260.6 307.1 279.5 252.0\n"
21422192
]
21432193
}
21442194
],
@@ -2217,14 +2267,24 @@
22172267
"text/markdown": [
22182268
"---\n",
22192269
"\n",
2220-
"### PartialFormatter\n",
2270+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L534){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
2271+
"\n",
2272+
"#### PartialFormatter\n",
22212273
"\n",
22222274
"> PartialFormatter ()\n",
22232275
"\n",
2224-
"A `string.Formatter` that doesn't error on missing fields, and tracks missing fields and unused args"
2276+
"*A `string.Formatter` that doesn't error on missing fields, and tracks missing fields and unused args*"
22252277
],
22262278
"text/plain": [
2227-
"<nbdev.showdoc.BasicMarkdownRenderer>"
2279+
"---\n",
2280+
"\n",
2281+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L534){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
2282+
"\n",
2283+
"#### PartialFormatter\n",
2284+
"\n",
2285+
"> PartialFormatter ()\n",
2286+
"\n",
2287+
"*A `string.Formatter` that doesn't error on missing fields, and tracks missing fields and unused args*"
22282288
]
22292289
},
22302290
"execution_count": null,
@@ -2290,7 +2350,7 @@
22902350
"name": "stdout",
22912351
"output_type": "stream",
22922352
"text": [
2293-
"2000-01-01 12:00:00 UTC is 2000-01-01 17:30:00+05:30 local time\n"
2353+
"2000-01-01 12:00:00 UTC is 2000-01-01 22:00:00+10:00 local time\n"
22942354
]
22952355
}
22962356
],
@@ -2320,7 +2380,7 @@
23202380
"name": "stdout",
23212381
"output_type": "stream",
23222382
"text": [
2323-
"2000-01-01 12:00:00 local is 2000-01-01 06:30:00+00:00 UTC time\n"
2383+
"2000-01-01 12:00:00 local is 2000-01-01 02:00:00+00:00 UTC time\n"
23242384
]
23252385
}
23262386
],
@@ -2423,14 +2483,24 @@
24232483
"text/markdown": [
24242484
"---\n",
24252485
"\n",
2426-
"### ContextManagers\n",
2486+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L591){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
2487+
"\n",
2488+
"#### ContextManagers\n",
24272489
"\n",
24282490
"> ContextManagers (mgrs)\n",
24292491
"\n",
2430-
"Wrapper for `contextlib.ExitStack` which enters a collection of context managers"
2492+
"*Wrapper for `contextlib.ExitStack` which enters a collection of context managers*"
24312493
],
24322494
"text/plain": [
2433-
"<nbdev.showdoc.BasicMarkdownRenderer>"
2495+
"---\n",
2496+
"\n",
2497+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/xtras.py#L591){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
2498+
"\n",
2499+
"#### ContextManagers\n",
2500+
"\n",
2501+
"> ContextManagers (mgrs)\n",
2502+
"\n",
2503+
"*Wrapper for `contextlib.ExitStack` which enters a collection of context managers*"
24342504
]
24352505
},
24362506
"execution_count": null,
@@ -2643,23 +2713,27 @@
26432713
"outputs": [],
26442714
"source": [
26452715
"#| export\n",
2646-
"def make_nullable(cls):\n",
2716+
"def make_nullable(clas):\n",
26472717
" from dataclasses import dataclass, fields, MISSING\n",
2648-
" if hasattr(cls, '_nullable'): return\n",
2649-
" cls._nullable = True\n",
2718+
" if hasattr(clas, '_nullable'): return\n",
2719+
" clas._nullable = True\n",
26502720
"\n",
2651-
" @patch\n",
2652-
" def __init__(self:cls, *args, **kwargs):\n",
2653-
" flds = fields(cls)\n",
2721+
" original_init = clas.__init__\n",
2722+
" def __init__(self, *args, **kwargs):\n",
2723+
" flds = fields(clas)\n",
26542724
" dargs = {k.name:v for k,v in zip(flds, args)}\n",
26552725
" for f in flds:\n",
26562726
" nm = f.name\n",
26572727
" if nm not in dargs and nm not in kwargs and f.default is None and f.default_factory is MISSING:\n",
26582728
" kwargs[nm] = None\n",
2659-
" self._orig___init__(*args, **kwargs)\n",
2729+
" original_init(self, *args, **kwargs)\n",
2730+
" \n",
2731+
" clas.__init__ = __init__\n",
2732+
"\n",
2733+
" for f in fields(clas):\n",
2734+
" if f.default is MISSING and f.default_factory is MISSING: f.default = None\n",
26602735
" \n",
2661-
" for f in fields(cls):\n",
2662-
" if f.default is MISSING and f.default_factory is MISSING: f.default = None"
2736+
" return clas"
26632737
]
26642738
},
26652739
{

settings.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ author = Jeremy Howard and Sylvain Gugger
88
author_email = infos@fast.ai
99
copyright = fast.ai
1010
branch = master
11-
version = 1.5.49
11+
version = 1.5.50
1212
min_python = 3.7
1313
audience = Developers
1414
language = English

0 commit comments

Comments
 (0)