-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support partials and tz.curry #316
Conversation
Codecov Report
@@ Coverage Diff @@
## main #316 +/- ##
==========================================
+ Coverage 90.24% 90.30% +0.06%
==========================================
Files 29 29
Lines 3301 3302 +1
==========================================
+ Hits 2979 2982 +3
+ Misses 322 320 -2
Continue to review full report at Codecov.
|
added support for In [1]: from functools import partial
In [2]: from toolz import curry
In [4]: def f(x: int, y: str): ...
In [5]: a = partial(f, y='hi')
In [6]: b = curry(f)(y='hi')
In [7]: import inspect
In [8]: inspect.signature(a)
Out[8]: <Signature (x: int, *, y: str = 'hi')>
In [9]: inspect.signature(b)
Out[9]: <Signature (x: int = '__no__default__', *, y: str = 'hi')> so we need to special case that here. @jni if you wanted to upstream anything, it would be to see whether they can use |
@tlambert03 where does parameter.empty come from exactly? |
(Also this is incredible, I thought my issue might eventually be fixed in a few months... 😂) |
In [1]: import inspect
In [2]: inspect.Parameter.empty
Out[2]: <class 'inspect._empty'> |
and... In [3]: def f(x): ...
In [4]: inspect.signature(f).parameters
Out[4]: mappingproxy({'x': <Parameter "x">})
In [5]: inspect.signature(f).parameters['x'].default
Out[5]: <class 'inspect._empty'> |
turned out to be relatively trivial! |
can I assume this is approved? wanna hit the button? :) |
This implements support for functions wrapped in functools.partial. closes #315
There is a slight "catch" ... which is really due to the way that partial handles signatures when providing positional vs keyword arguments. Take this example
wdg1 will look like this:

and wdg2 will look like thisthey both behave like the corresponding partials. but wdg2 shows the widget for
y
, whereaswdg
doesn't showx
To avoid that behavior automatically, we'd need to do a little special casing. It's possible, but prefer to leave to another PR