-
Notifications
You must be signed in to change notification settings - Fork 586
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
st.functions() returning consistent (or pure) functions
#2538
Comments
st.functions() returning consistent functionsst.functions() returning consistent (or pure) functions
|
Generating pure functions is a little tricky - I think in general we could only support it based on hashing the arguments, and mutable return values wouldn't be regenerated. If you think it's useful though, there's a demo at master...Zac-HD:pure-functions and it seems to work. Needs much more testing before it could be merged though 😅 |
|
@Zac-HD is there anything I can help you with? P.S. does my solution look viable for now? |
|
Actually, yes - if you want to copy that branch and add tests + release notes, I'd be happy to merge it. All the tests can go in
Your workaround looks OK to me, with the caveats that I think it fails for |
|
I am on it! 👍 |
Currently,
st.functions()creates functions that are not-pure (in a sence that they don't return the same value for the same arguments).My use-case is that I am testing monad laws (see dry-python/returns#533 and dry-python/returns#543 for more information). Here's one of the definitions:
And it never passes! Because each time
first(x)andsecond(y)returns a different result.My work-around for now is this custom strategy:
And then I register this callback to handle
Callable, like so:st.register_type_strategy(Callable, custom_strategies.functions(data))So, is there any chance to see pure functions in the core of
st.functions()?The text was updated successfully, but these errors were encountered: