Skip to content

Commit

Permalink
Merge pull request #459 from EmbraceLife/master
Browse files Browse the repository at this point in the history
enable meta.delegates to enforce KEYWORD_ONLY for kwargs from
  • Loading branch information
jph00 authored Aug 11, 2022
2 parents 9e4874c + 41131f0 commit 0a94e22
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion fastcore/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def _f(f):
sig = inspect.signature(from_f)
sigd = dict(sig.parameters)
k = sigd.pop('kwargs')
s2 = {k:v for k,v in inspect.signature(to_f).parameters.items()
s2 = {k:v.replace(kind=inspect.Parameter.KEYWORD_ONLY) for k,v in inspect.signature(to_f).parameters.items()
if v.default != inspect.Parameter.empty and k not in sigd and k not in but}
sigd.update(s2)
if keep: sigd['kwargs'] = k
Expand Down
16 changes: 8 additions & 8 deletions nbs/07_meta.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@
" sig = inspect.signature(from_f)\n",
" sigd = dict(sig.parameters)\n",
" k = sigd.pop('kwargs')\n",
" s2 = {k:v for k,v in inspect.signature(to_f).parameters.items()\n",
" s2 = {k:v.replace(kind=inspect.Parameter.KEYWORD_ONLY) for k,v in inspect.signature(to_f).parameters.items()\n",
" if v.default != inspect.Parameter.empty and k not in sigd and k not in but}\n",
" sigd.update(s2)\n",
" if keep: sigd['kwargs'] = k\n",
Expand Down Expand Up @@ -966,7 +966,7 @@
"def foo(c, a, **kwargs):\n",
" return c + baz(a, **kwargs)\n",
"\n",
"test_sig(foo, '(c, a, b=2)')\n",
"test_sig(foo, '(c, a, *, b=2)')\n",
"inspect.signature(foo)"
]
},
Expand Down Expand Up @@ -998,7 +998,7 @@
"def foo(c, a, **kwargs):\n",
" return c + baz(a, **kwargs)\n",
"\n",
"test_sig(foo, '(c, a, b=2, **kwargs)')\n",
"test_sig(foo, '(c, a, *, b=2, **kwargs)')\n",
"inspect.signature(foo)"
]
},
Expand Down Expand Up @@ -1030,7 +1030,7 @@
"\n",
"@delegates(basefoo)\n",
"def foo(a, b=1, **kwargs): pass\n",
"test_sig(foo, '(a, b=1, c=2)') # e and d are not included b/c they don't have default parameters.\n",
"test_sig(foo, '(a, b=1, *, c=2)') # e and d are not included b/c they don't have default parameters.\n",
"inspect.signature(foo)"
]
},
Expand Down Expand Up @@ -1065,7 +1065,7 @@
"@delegates(basefoo, but= ['d'])\n",
"def foo(a, b=1, **kwargs): pass\n",
"\n",
"test_sig(foo, '(a, b=1, c=2)')\n",
"test_sig(foo, '(a, b=1, *, c=2)')\n",
"inspect.signature(foo)"
]
},
Expand Down Expand Up @@ -1093,7 +1093,7 @@
" def bar(cls, c=3, **kwargs):\n",
" pass\n",
"\n",
"test_sig(_T.bar, '(c=3, a=1, b=2)')"
"test_sig(_T.bar, '(c=3, *, a=1, b=2)')"
]
},
{
Expand All @@ -1119,7 +1119,7 @@
" pass\n",
"\n",
"t = _T()\n",
"test_sig(t.bar, '(c=3, a=1, b=2)')"
"test_sig(t.bar, '(c=3, *, a=1, b=2)')"
]
},
{
Expand All @@ -1142,7 +1142,7 @@
"class Foo(BaseFoo):\n",
" def __init__(self, a, b=1, **kwargs): super().__init__(**kwargs)\n",
"\n",
"test_sig(Foo, '(a, b=1, c=2)')"
"test_sig(Foo, '(a, b=1, *, c=2)')"
]
},
{
Expand Down

0 comments on commit 0a94e22

Please sign in to comment.