Skip to content

Commit

Permalink
Merge pull request #6 from rbracco/delegates
Browse files Browse the repository at this point in the history
Fix nested delegation
  • Loading branch information
jph00 committed Jan 27, 2020
2 parents 5b14c80 + 5de677e commit c310dda
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion fastcore/foundation.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ def _f(f):
if v.default != inspect.Parameter.empty and k not in sigd}
sigd.update(s2)
if keep: sigd['kwargs'] = k
else: from_f.__delwrap__ = to_f
from_f.__signature__ = sig.replace(parameters=sigd.values())
from_f.__delwrap__ = to_f
return f
return _f

Expand Down
38 changes: 19 additions & 19 deletions nbs/01_foundation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@
"metadata": {},
"outputs": [],
"source": [
"#export\n",
"# export\n",
"def delegates(to=None, keep=False):\n",
" \"Decorator: replace `**kwargs` in signature with params from `to`\"\n",
" def _f(f):\n",
Expand All @@ -507,8 +507,8 @@
" if v.default != inspect.Parameter.empty and k not in sigd}\n",
" sigd.update(s2)\n",
" if keep: sigd['kwargs'] = k\n",
" else: from_f.__delwrap__ = to_f\n",
" from_f.__signature__ = sig.replace(parameters=sigd.values())\n",
" from_f.__delwrap__ = to_f\n",
" return f\n",
" return _f"
]
Expand Down Expand Up @@ -1742,7 +1742,7 @@
"\n",
"> <code>L.map</code>(**`f`**, **\\*`args`**, **\\*\\*`kwargs`**)\n",
"\n",
"Create new [`L`](foundation.html#L) with `f` applied to all `items`, passing `args` and `kwargs` to `f`"
"Create new [`L`](/foundation#L) with `f` applied to all `items`, passing `args` and `kwargs` to `f`"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
Expand Down Expand Up @@ -1832,7 +1832,7 @@
{
"data": {
"text/markdown": [
"<h4 id=\"L.map_dict\" class=\"doc_header\"><code>L.map_dict</code><a href=\"__main__.py#L82\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"<h4 id=\"L.map_dict\" class=\"doc_header\"><code>L.map_dict</code><a href=\"__main__.py#L87\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"\n",
"> <code>L.map_dict</code>(**`f`**=*`'noop'`*, **\\*`args`**, **\\*\\*`kwargs`**)\n",
"\n",
Expand Down Expand Up @@ -1868,11 +1868,11 @@
{
"data": {
"text/markdown": [
"<h4 id=\"L.zip\" class=\"doc_header\"><code>L.zip</code><a href=\"__main__.py#L84\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"<h4 id=\"L.zip\" class=\"doc_header\"><code>L.zip</code><a href=\"__main__.py#L89\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"\n",
"> <code>L.zip</code>(**`cycled`**=*`False`*)\n",
"\n",
"Create new [`L`](foundation.html#L) with `zip(*items)`"
"Create new [`L`](/foundation#L) with `zip(*items)`"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
Expand Down Expand Up @@ -1915,7 +1915,7 @@
{
"data": {
"text/markdown": [
"<h4 id=\"L.map_zip\" class=\"doc_header\"><code>L.map_zip</code><a href=\"__main__.py#L86\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"<h4 id=\"L.map_zip\" class=\"doc_header\"><code>L.map_zip</code><a href=\"__main__.py#L91\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"\n",
"> <code>L.map_zip</code>(**`f`**, **\\*`args`**, **`cycled`**=*`False`*, **\\*\\*`kwargs`**)\n",
"\n",
Expand Down Expand Up @@ -1951,11 +1951,11 @@
{
"data": {
"text/markdown": [
"<h4 id=\"L.zipwith\" class=\"doc_header\"><code>L.zipwith</code><a href=\"__main__.py#L85\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"<h4 id=\"L.zipwith\" class=\"doc_header\"><code>L.zipwith</code><a href=\"__main__.py#L90\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"\n",
"> <code>L.zipwith</code>(**\\*`rest`**, **`cycled`**=*`False`*)\n",
"\n",
"Create new [`L`](foundation.html#L) with `self` zip with each of `*rest`"
"Create new [`L`](/foundation#L) with `self` zip with each of `*rest`"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
Expand Down Expand Up @@ -1988,7 +1988,7 @@
{
"data": {
"text/markdown": [
"<h4 id=\"L.map_zipwith\" class=\"doc_header\"><code>L.map_zipwith</code><a href=\"__main__.py#L87\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"<h4 id=\"L.map_zipwith\" class=\"doc_header\"><code>L.map_zipwith</code><a href=\"__main__.py#L92\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"\n",
"> <code>L.map_zipwith</code>(**`f`**, **\\*`rest`**, **`cycled`**=*`False`*, **\\*\\*`kwargs`**)\n",
"\n",
Expand Down Expand Up @@ -2023,11 +2023,11 @@
{
"data": {
"text/markdown": [
"<h4 id=\"L.itemgot\" class=\"doc_header\"><code>L.itemgot</code><a href=\"__main__.py#L75\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"<h4 id=\"L.itemgot\" class=\"doc_header\"><code>L.itemgot</code><a href=\"__main__.py#L80\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"\n",
"> <code>L.itemgot</code>(**\\*`idxs`**)\n",
"\n",
"Create new [`L`](foundation.html#L) with item `idx` of all `items`"
"Create new [`L`](/foundation#L) with item `idx` of all `items`"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
Expand Down Expand Up @@ -2058,11 +2058,11 @@
{
"data": {
"text/markdown": [
"<h4 id=\"L.attrgot\" class=\"doc_header\"><code>L.attrgot</code><a href=\"__main__.py#L80\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"<h4 id=\"L.attrgot\" class=\"doc_header\"><code>L.attrgot</code><a href=\"__main__.py#L85\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"\n",
"> <code>L.attrgot</code>(**`k`**, **`default`**=*`None`*)\n",
"\n",
"Create new [`L`](foundation.html#L) with attr `k` of all `items`"
"Create new [`L`](/foundation#L) with attr `k` of all `items`"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
Expand Down Expand Up @@ -2098,7 +2098,7 @@
"\n",
"> <code>L.sorted</code>(**`key`**=*`None`*, **`reverse`**=*`False`*)\n",
"\n",
"New [`L`](foundation.html#L) sorted by `key`. If key is str then use `attrgetter`. If key is int then use `itemgetter`"
"New [`L`](/foundation#L) sorted by `key`. If key is str then use `attrgetter`. If key is int then use `itemgetter`"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
Expand Down Expand Up @@ -2133,7 +2133,7 @@
"\n",
"> <code>L.split</code>(**`s`**, **`sep`**=*`None`*, **`maxsplit`**=*`-1`*)\n",
"\n",
"Same as `str.split`, but returns an [`L`](foundation.html#L)"
"Same as `str.split`, but returns an [`L`](/foundation#L)"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
Expand Down Expand Up @@ -2168,7 +2168,7 @@
"\n",
"> <code>L.range</code>(**`a`**, **`b`**=*`None`*, **`step`**=*`None`*)\n",
"\n",
"Same as `range`, but returns an [`L`](foundation.html#L). Can pass a collection for `a`, to use `len(a)`"
"Same as `range`, but returns an [`L`](/foundation#L). Can pass a collection for `a`, to use `len(a)`"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
Expand Down Expand Up @@ -2200,7 +2200,7 @@
{
"data": {
"text/markdown": [
"<h4 id=\"L.concat\" class=\"doc_header\"><code>L.concat</code><a href=\"__main__.py#L88\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"<h4 id=\"L.concat\" class=\"doc_header\"><code>L.concat</code><a href=\"__main__.py#L93\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"\n",
"> <code>L.concat</code>()\n",
"\n",
Expand Down Expand Up @@ -2239,7 +2239,7 @@
"\n",
"> <code>L.copy</code>()\n",
"\n",
"Same as `list.copy`, but returns an [`L`](foundation.html#L)"
"Same as `list.copy`, but returns an [`L`](/foundation#L)"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
Expand Down

0 comments on commit c310dda

Please sign in to comment.