![](https://secure.gravatar.com/avatar/870d613430249e453343efc9667ef636.jpg?s=120&d=mm&r=g)
On 01/26/2016 04:51 PM, Chris Angelico wrote:
On Wed, Jan 27, 2016 at 2:42 AM, Paul Moore <p.f.moore@gmail.com> wrote:
On 26 January 2016 at 15:24, Chris Angelico <rosuav@gmail.com> wrote:
This still has one nasty problem though: the requires and ensures functions can't see function arguments.
See my code - you can put the args onto the instance as attributes for requires/ensures to inspect.
Except that there can be only one of those at any given time, so you run into issues with recursion or threads/async/etc; plus, it's still not properly clean - you have to check either args or kwargs, depending on whether the argument was passed positionally or by keyword. I don't see that as a solution.
(Maybe what we need is a "keyword-to-positional" functools feature - anything in **kwargs that can be interpreted positionally gets removed and added to *args. Or the other way - keywordify everything.)
Well, it's not in functools. import inspect def keyword_to_positional(func, args, kwargs): sig = inspect.signature(func).bind(*args, **kwargs) sig.apply_defaults() return sig.args, sig.kwargs def keywordify_everything(func, args, kwargs): sig = inspect.signature(func).bind(*args, **kwargs) sig.apply_defaults() return sig.arguments