You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am looking now into how to rewrite contracts using the **kwargs -> fixed_dictionaries() and consequential .filter(.) chain. This is relevant for multi-argument preconditions which need to be transformed into multi-argument filters.
I suppose the filter function would now need to take only a single argument, the whole dictionary? Consider the following example where we have a function taking two integers, x and y, and preconditions x < y and x + y < 1000, transformed into a strategy:
In my case (icontract), the conditions are lambdas whose arguments are directly tied to the function argument names (such as lambda x, y: x < y). If I want to transform them into Hypothesis filters programatically, I would need to parse them, rewrite them and recompile them on the fly. This is quite complex, and tedious to program as naming conflicts need to be avoided (e.g., the precondition might use the global variable d which I intended for the name of the dictionary argument).
Are there maybe some other ways that already exist in Hypothesis that such preconditions can be filtered and that it will be easy for Hypothesis to optimize them in the future (once the optimization on multi-argument filters has been implemented)?
For example, using a separate function would most probably impede the optimization:
I suppose the filter function would now need to take only a single argument, the whole dictionary?
That's correct, and e.g. .filter(lambda d: d['x'] < d['y']) is an idiomatic example - though as you say, difficult to automatically construct.
Are there maybe some other ways that already exist in Hypothesis that such preconditions can be filtered and that it will be easy for Hypothesis to optimize them in the future (once the optimization on multi-argument filters has been implemented)?
We don't (yet?) have any such function, and at this stage my advice would be to ignore any rewriting concerns and just get it working nicely for you. For example you can use inspect.signature(condition).parameters instead of a condition_args argument... we'll work out the integration later, and can always special-case the icontract idiom if that's what it takes 🙂
(closing because I don't think there's any action for this issue which isn't already covered by #2701)
I am looking now into how to rewrite contracts using the
**kwargs -> fixed_dictionaries()
and consequential.filter(.)
chain. This is relevant for multi-argument preconditions which need to be transformed into multi-argument filters.I suppose the
filter
function would now need to take only a single argument, the whole dictionary? Consider the following example where we have a function taking two integers, x and y, and preconditionsx < y
andx + y < 1000
, transformed into a strategy:In my case (icontract), the conditions are lambdas whose arguments are directly tied to the function argument names (such as
lambda x, y: x < y
). If I want to transform them into Hypothesis filters programatically, I would need to parse them, rewrite them and recompile them on the fly. This is quite complex, and tedious to program as naming conflicts need to be avoided (e.g., the precondition might use the global variabled
which I intended for the name of the dictionary argument).Are there maybe some other ways that already exist in Hypothesis that such preconditions can be filtered and that it will be easy for Hypothesis to optimize them in the future (once the optimization on multi-argument filters has been implemented)?
For example, using a separate function would most probably impede the optimization:
which gives us the transformtion:
(This issue is related to the issue #2701.)
The text was updated successfully, but these errors were encountered: