Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

make patch more compatible with classmethods #309

Merged
merged 2 commits into from
Apr 28, 2021
Merged
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
1 change: 1 addition & 0 deletions fastcore/basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,7 @@ def patch(f=None, *, as_prop=False, cls_method=False):
"Decorator: add `f` to the first parameter's class (based on f's type annotations)"
if f is None: return partial(patch, as_prop=as_prop, cls_method=cls_method)
cls = next(iter(f.__annotations__.values()))
if cls_method: cls = f.__annotations__.pop('cls')
return patch_to(cls, as_prop=as_prop, cls_method=cls_method)(f)

# Cell
Expand Down
19 changes: 10 additions & 9 deletions nbs/01_basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2913,7 +2913,7 @@
{
"data": {
"text/plain": [
"{1: [0], 3: [0, 2], 7: [0], 5: [3, 7], 8: [4], 4: [5]}"
"{1: [0], 3: [0, 2], 4: [5], 5: [3, 7], 7: [0], 8: [4]}"
]
},
"execution_count": null,
Expand Down Expand Up @@ -4452,6 +4452,7 @@
" \"Decorator: add `f` to the first parameter's class (based on f's type annotations)\"\n",
" if f is None: return partial(patch, as_prop=as_prop, cls_method=cls_method)\n",
" cls = next(iter(f.__annotations__.values()))\n",
" if cls_method: cls = f.__annotations__.pop('cls')\n",
" return patch_to(cls, as_prop=as_prop, cls_method=cls_method)(f)"
]
},
Expand Down Expand Up @@ -4637,7 +4638,7 @@
"\n",
"> <code>Enum</code> = []\n",
"\n",
"An `ImportEnum` that behaves like a `str`"
"An [`ImportEnum`](/basics.html#ImportEnum) that behaves like a `str`"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
Expand Down Expand Up @@ -4956,7 +4957,7 @@
{
"data": {
"text/plain": [
"12"
"4"
]
},
"execution_count": null,
Expand Down Expand Up @@ -5148,7 +5149,7 @@
{
"data": {
"text/markdown": [
"<h4 id=\"ipython_shell\" class=\"doc_header\"><code>ipython_shell</code><a href=\"https://github.com/fastai/fastcore/tree/master/fastcore/imports.py#L67\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"<h4 id=\"ipython_shell\" class=\"doc_header\"><code>ipython_shell</code><a href=\"https://github.com/fastai/fastcore/tree/master/fastcore/imports.py#L70\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"\n",
"> <code>ipython_shell</code>()\n",
"\n",
Expand All @@ -5174,7 +5175,7 @@
{
"data": {
"text/markdown": [
"<h4 id=\"in_ipython\" class=\"doc_header\"><code>in_ipython</code><a href=\"https://github.com/fastai/fastcore/tree/master/fastcore/imports.py#L72\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"<h4 id=\"in_ipython\" class=\"doc_header\"><code>in_ipython</code><a href=\"https://github.com/fastai/fastcore/tree/master/fastcore/imports.py#L75\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"\n",
"> <code>in_ipython</code>()\n",
"\n",
Expand All @@ -5200,7 +5201,7 @@
{
"data": {
"text/markdown": [
"<h4 id=\"in_colab\" class=\"doc_header\"><code>in_colab</code><a href=\"https://github.com/fastai/fastcore/tree/master/fastcore/imports.py#L76\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"<h4 id=\"in_colab\" class=\"doc_header\"><code>in_colab</code><a href=\"https://github.com/fastai/fastcore/tree/master/fastcore/imports.py#L79\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"\n",
"> <code>in_colab</code>()\n",
"\n",
Expand All @@ -5226,7 +5227,7 @@
{
"data": {
"text/markdown": [
"<h4 id=\"in_jupyter\" class=\"doc_header\"><code>in_jupyter</code><a href=\"https://github.com/fastai/fastcore/tree/master/fastcore/imports.py#L80\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"<h4 id=\"in_jupyter\" class=\"doc_header\"><code>in_jupyter</code><a href=\"https://github.com/fastai/fastcore/tree/master/fastcore/imports.py#L83\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"\n",
"> <code>in_jupyter</code>()\n",
"\n",
Expand All @@ -5252,7 +5253,7 @@
{
"data": {
"text/markdown": [
"<h4 id=\"in_notebook\" class=\"doc_header\"><code>in_notebook</code><a href=\"https://github.com/fastai/fastcore/tree/master/fastcore/imports.py#L85\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"<h4 id=\"in_notebook\" class=\"doc_header\"><code>in_notebook</code><a href=\"https://github.com/fastai/fastcore/tree/master/fastcore/imports.py#L88\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"\n",
"> <code>in_notebook</code>()\n",
"\n",
Expand Down Expand Up @@ -5285,7 +5286,7 @@
{
"data": {
"text/plain": [
"(True, True, False, True)"
"(True, False, True, True)"
]
},
"execution_count": null,
Expand Down