Last active
September 12, 2022 19:17
-
-
Save michaelaye/2a7912d2c44051f40ade20a8636a0325 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from fastcore.basics import store_attr" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 13, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"class A:\n", | |
" aa = 4" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 18, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"class B:\n", | |
" def __init__(self, a, b=3, c=5):\n", | |
" store_attr()\n", | |
" self.a_obj = A()\n", | |
"\n", | |
" def __getattr__(self, attr):\n", | |
" return getattr(self.a_obj, attr)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 19, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"ename": "RecursionError", | |
"evalue": "maximum recursion depth exceeded", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mRecursionError\u001b[0m Traceback (most recent call last)", | |
"\u001b[1;32mUntitled-1.ipynb Cell 4\u001b[0m in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> <a href='vscode-notebook-cell:Untitled-1.ipynb?jupyter-notebook#W3sdW50aXRsZWQ%3D?line=0'>1</a>\u001b[0m b \u001b[39m=\u001b[39m B(\u001b[39m1\u001b[39;49m)\n", | |
"\u001b[1;32mUntitled-1.ipynb Cell 4\u001b[0m in \u001b[0;36mB.__init__\u001b[0;34m(self, a, b, c)\u001b[0m\n\u001b[1;32m <a href='vscode-notebook-cell:Untitled-1.ipynb?jupyter-notebook#W3sdW50aXRsZWQ%3D?line=1'>2</a>\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__init__\u001b[39m(\u001b[39mself\u001b[39m, a, b\u001b[39m=\u001b[39m\u001b[39m3\u001b[39m, c\u001b[39m=\u001b[39m\u001b[39m5\u001b[39m):\n\u001b[0;32m----> <a href='vscode-notebook-cell:Untitled-1.ipynb?jupyter-notebook#W3sdW50aXRsZWQ%3D?line=2'>3</a>\u001b[0m store_attr()\n\u001b[1;32m <a href='vscode-notebook-cell:Untitled-1.ipynb?jupyter-notebook#W3sdW50aXRsZWQ%3D?line=3'>4</a>\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39ma_obj \u001b[39m=\u001b[39m A()\n", | |
"File \u001b[0;32m~/mambaforge/envs/py310/lib/python3.10/site-packages/fastcore/basics.py:399\u001b[0m, in \u001b[0;36mstore_attr\u001b[0;34m(names, self, but, cast, store_args, **attrs)\u001b[0m\n\u001b[1;32m 397\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m: args \u001b[39m=\u001b[39m (\u001b[39m'\u001b[39m\u001b[39mself\u001b[39m\u001b[39m'\u001b[39m, \u001b[39m*\u001b[39margs)\n\u001b[1;32m 398\u001b[0m \u001b[39melse\u001b[39;00m: \u001b[39mself\u001b[39m \u001b[39m=\u001b[39m fr\u001b[39m.\u001b[39mf_locals[args[\u001b[39m0\u001b[39m]]\n\u001b[0;32m--> 399\u001b[0m \u001b[39mif\u001b[39;00m store_args \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m: store_args \u001b[39m=\u001b[39m \u001b[39mnot\u001b[39;00m \u001b[39mhasattr\u001b[39;49m(\u001b[39mself\u001b[39;49m,\u001b[39m'\u001b[39;49m\u001b[39m__slots__\u001b[39;49m\u001b[39m'\u001b[39;49m)\n\u001b[1;32m 400\u001b[0m \u001b[39mif\u001b[39;00m store_args \u001b[39mand\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mhasattr\u001b[39m(\u001b[39mself\u001b[39m, \u001b[39m'\u001b[39m\u001b[39m__stored_args__\u001b[39m\u001b[39m'\u001b[39m): \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m__stored_args__ \u001b[39m=\u001b[39m {}\n\u001b[1;32m 401\u001b[0m anno \u001b[39m=\u001b[39m annotations(\u001b[39mself\u001b[39m) \u001b[39mif\u001b[39;00m cast \u001b[39melse\u001b[39;00m {}\n", | |
"\u001b[1;32mUntitled-1.ipynb Cell 4\u001b[0m in \u001b[0;36mB.__getattr__\u001b[0;34m(self, attr)\u001b[0m\n\u001b[1;32m <a href='vscode-notebook-cell:Untitled-1.ipynb?jupyter-notebook#W3sdW50aXRsZWQ%3D?line=5'>6</a>\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__getattr__\u001b[39m(\u001b[39mself\u001b[39m, attr):\n\u001b[0;32m----> <a href='vscode-notebook-cell:Untitled-1.ipynb?jupyter-notebook#W3sdW50aXRsZWQ%3D?line=6'>7</a>\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mgetattr\u001b[39m(\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49ma_obj, attr)\n", | |
"\u001b[1;32mUntitled-1.ipynb Cell 4\u001b[0m in \u001b[0;36mB.__getattr__\u001b[0;34m(self, attr)\u001b[0m\n\u001b[1;32m <a href='vscode-notebook-cell:Untitled-1.ipynb?jupyter-notebook#W3sdW50aXRsZWQ%3D?line=5'>6</a>\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__getattr__\u001b[39m(\u001b[39mself\u001b[39m, attr):\n\u001b[0;32m----> <a href='vscode-notebook-cell:Untitled-1.ipynb?jupyter-notebook#W3sdW50aXRsZWQ%3D?line=6'>7</a>\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mgetattr\u001b[39m(\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49ma_obj, attr)\n", | |
" \u001b[0;31m[... skipping similar frames: B.__getattr__ at line 7 (2966 times)]\u001b[0m\n", | |
"\u001b[1;32mUntitled-1.ipynb Cell 4\u001b[0m in \u001b[0;36mB.__getattr__\u001b[0;34m(self, attr)\u001b[0m\n\u001b[1;32m <a href='vscode-notebook-cell:Untitled-1.ipynb?jupyter-notebook#W3sdW50aXRsZWQ%3D?line=5'>6</a>\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__getattr__\u001b[39m(\u001b[39mself\u001b[39m, attr):\n\u001b[0;32m----> <a href='vscode-notebook-cell:Untitled-1.ipynb?jupyter-notebook#W3sdW50aXRsZWQ%3D?line=6'>7</a>\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mgetattr\u001b[39m(\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49ma_obj, attr)\n", | |
"\u001b[0;31mRecursionError\u001b[0m: maximum recursion depth exceeded" | |
] | |
} | |
], | |
"source": [ | |
"b = B(1)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3.10.6 ('py310')", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.10.6" | |
}, | |
"orig_nbformat": 4, | |
"vscode": { | |
"interpreter": { | |
"hash": "b601bea36bc04655dd054ecad9c64f12db1fd2a18968d4dbaa5f76ee3262ec06" | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment