Skip to content

Commit

Permalink
fixes #267
Browse files Browse the repository at this point in the history
  • Loading branch information
jph00 committed Dec 22, 2020
1 parent 8731b46 commit fe2d09f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fastcore/basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def store_attr(names=None, self=None, but='', cast=False, store_args=None, **att
if store_args and not hasattr(self, '__stored_args__'): self.__stored_args__ = {}
anno = annotations(self) if cast else {}
if names and isinstance(names,str): names = re.split(', *', names)
ns = names if names else getattr(self, '__slots__', args[1:])
ns = names if names is not None else getattr(self, '__slots__', args[1:])
added = {n:fr.f_locals[n] for n in ns}
attrs = {**attrs, **added}
if isinstance(but,str): but = re.split(', *', but)
Expand Down
20 changes: 19 additions & 1 deletion nbs/01_basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,7 @@
" if store_args and not hasattr(self, '__stored_args__'): self.__stored_args__ = {}\n",
" anno = annotations(self) if cast else {}\n",
" if names and isinstance(names,str): names = re.split(', *', names)\n",
" ns = names if names else getattr(self, '__slots__', args[1:])\n",
" ns = names if names is not None else getattr(self, '__slots__', args[1:])\n",
" added = {n:fr.f_locals[n] for n in ns}\n",
" attrs = {**attrs, **added}\n",
" if isinstance(but,str): but = re.split(', *', but)\n",
Expand Down Expand Up @@ -1847,6 +1847,24 @@
"assert t.a==1 and t.b==3 and t.c==2 and t.d==4 and t.e==-1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#hide\n",
"#ensure that kwargs work with names==''\n",
"class T:\n",
" def __init__(self, a, **kwargs):\n",
" self.a = a+1\n",
" store_attr('', **kwargs)\n",
"\n",
"t = T(a=1, d=4)\n",
"test_eq(t.a, 2)\n",
"test_eq(t.d, 4)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down

0 comments on commit fe2d09f

Please sign in to comment.