Skip to content

Commit fe2d09f

Browse files
committed
fixes #267
1 parent 8731b46 commit fe2d09f

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

fastcore/basics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def store_attr(names=None, self=None, but='', cast=False, store_args=None, **att
297297
if store_args and not hasattr(self, '__stored_args__'): self.__stored_args__ = {}
298298
anno = annotations(self) if cast else {}
299299
if names and isinstance(names,str): names = re.split(', *', names)
300-
ns = names if names else getattr(self, '__slots__', args[1:])
300+
ns = names if names is not None else getattr(self, '__slots__', args[1:])
301301
added = {n:fr.f_locals[n] for n in ns}
302302
attrs = {**attrs, **added}
303303
if isinstance(but,str): but = re.split(', *', but)

nbs/01_basics.ipynb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1606,7 +1606,7 @@
16061606
" if store_args and not hasattr(self, '__stored_args__'): self.__stored_args__ = {}\n",
16071607
" anno = annotations(self) if cast else {}\n",
16081608
" if names and isinstance(names,str): names = re.split(', *', names)\n",
1609-
" ns = names if names else getattr(self, '__slots__', args[1:])\n",
1609+
" ns = names if names is not None else getattr(self, '__slots__', args[1:])\n",
16101610
" added = {n:fr.f_locals[n] for n in ns}\n",
16111611
" attrs = {**attrs, **added}\n",
16121612
" if isinstance(but,str): but = re.split(', *', but)\n",
@@ -1847,6 +1847,24 @@
18471847
"assert t.a==1 and t.b==3 and t.c==2 and t.d==4 and t.e==-1"
18481848
]
18491849
},
1850+
{
1851+
"cell_type": "code",
1852+
"execution_count": null,
1853+
"metadata": {},
1854+
"outputs": [],
1855+
"source": [
1856+
"#hide\n",
1857+
"#ensure that kwargs work with names==''\n",
1858+
"class T:\n",
1859+
" def __init__(self, a, **kwargs):\n",
1860+
" self.a = a+1\n",
1861+
" store_attr('', **kwargs)\n",
1862+
"\n",
1863+
"t = T(a=1, d=4)\n",
1864+
"test_eq(t.a, 2)\n",
1865+
"test_eq(t.d, 4)"
1866+
]
1867+
},
18501868
{
18511869
"cell_type": "markdown",
18521870
"metadata": {},

0 commit comments

Comments
 (0)