Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fastcore/basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def store_attr(names=None, self=None, but='', cast=False, store_args=None, **att
anno = annotations(self) if cast else {}
if names and isinstance(names,str): names = re.split(', *', names)
ns = names if names is not None else getattr(self, '__slots__', args[1:])
added = {n:fr.f_locals[n] for n in ns}
added = {n: getattr(self, n, fr.f_locals[n]) for n in ns}
attrs = {**attrs, **added}
if isinstance(but,str): but = re.split(', *', but)
attrs = {k:v for k,v in attrs.items() if k not in but}
Expand Down
84 changes: 47 additions & 37 deletions nbs/01_basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,31 @@
"execution_count": null,
"id": "da11467b",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/markdown": [
"---\n",
"\n",
"[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/basics.py#L198){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"\n",
"### Inf\n",
"\n",
"> Inf ()\n",
"\n",
"*Infinite lists*"
],
"text/plain": [
"> Inf ()\n",
"\n",
"*Infinite lists*"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"show_doc(Inf);"
]
Expand Down Expand Up @@ -2355,7 +2379,7 @@
" anno = annotations(self) if cast else {}\n",
" if names and isinstance(names,str): names = re.split(', *', names)\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",
" added = {n: getattr(self, n, fr.f_locals[n]) for n in ns}\n",
" attrs = {**attrs, **added}\n",
" if isinstance(but,str): but = re.split(', *', but)\n",
" attrs = {k:v for k,v in attrs.items() if k not in but}\n",
Expand Down Expand Up @@ -2487,6 +2511,24 @@
"assert t.a==1 and t.b==3 and t.c==2"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fe78248d",
"metadata": {},
"outputs": [],
"source": [
"#| hide\n",
"#| hide\n",
"class T_:\n",
" def __init__(self, a, b, c):\n",
" self.a = a - 1\n",
" store_attr()\n",
"\n",
"t = T_(5, 2, 3)\n",
"assert t.a==4 and t.b==2 and t.c==3"
]
},
{
"cell_type": "markdown",
"id": "6e2f9137",
Expand Down Expand Up @@ -6825,7 +6867,7 @@
"text/markdown": [
"---\n",
"\n",
"[source](https://github.com/AnswerDotAI/fastcore/blob/master/fastcore/basics.py#L1140){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/basics.py#L1158){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"\n",
"#### PrettyString\n",
"\n",
Expand All @@ -6834,12 +6876,6 @@
"*Little hack to get strings to show properly in Jupyter.*"
],
"text/plain": [
"---\n",
"\n",
"[source](https://github.com/AnswerDotAI/fastcore/blob/master/fastcore/basics.py#L1140){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"\n",
"#### PrettyString\n",
"\n",
"\n",
"\n",
"*Little hack to get strings to show properly in Jupyter.*"
Expand Down Expand Up @@ -6969,7 +7005,7 @@
{
"data": {
"text/plain": [
"22"
"24"
]
},
"execution_count": null,
Expand Down Expand Up @@ -7530,10 +7566,6 @@
"*Same as `get_ipython` but returns `False` if not in IPython*"
],
"text/plain": [
"---\n",
"\n",
"### ipython_shell\n",
"\n",
"> ipython_shell ()\n",
"\n",
"*Same as `get_ipython` but returns `False` if not in IPython*"
Expand Down Expand Up @@ -7566,10 +7598,6 @@
"*Check if code is running in some kind of IPython environment*"
],
"text/plain": [
"---\n",
"\n",
"### in_ipython\n",
"\n",
"> in_ipython ()\n",
"\n",
"*Check if code is running in some kind of IPython environment*"
Expand Down Expand Up @@ -7602,10 +7630,6 @@
"*Check if the code is running in Google Colaboratory*"
],
"text/plain": [
"---\n",
"\n",
"### in_colab\n",
"\n",
"> in_colab ()\n",
"\n",
"*Check if the code is running in Google Colaboratory*"
Expand Down Expand Up @@ -7638,10 +7662,6 @@
"*Check if the code is running in a jupyter notebook*"
],
"text/plain": [
"---\n",
"\n",
"### in_jupyter\n",
"\n",
"> in_jupyter ()\n",
"\n",
"*Check if the code is running in a jupyter notebook*"
Expand Down Expand Up @@ -7674,10 +7694,6 @@
"*Check if the code is running in a jupyter notebook*"
],
"text/plain": [
"---\n",
"\n",
"### in_notebook\n",
"\n",
"> in_notebook ()\n",
"\n",
"*Check if the code is running in a jupyter notebook*"
Expand Down Expand Up @@ -7749,13 +7765,7 @@
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "python3",
"language": "python",
"name": "python3"
}
},
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}