Skip to content
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

Allow exact values in st.builds() arguments #3775

Closed
ketozhang opened this issue Oct 24, 2023 · 2 comments
Closed

Allow exact values in st.builds() arguments #3775

ketozhang opened this issue Oct 24, 2023 · 2 comments

Comments

@ketozhang
Copy link

ketozhang commented Oct 24, 2023

Are there any strong opposition to allowing non-strategy objects in st.builds() positional and keyword arguments to be handled as exact values (i.e., as if it was passed in with st.just()?

Current Behavior

@given(st.builds(MyClass, x=st.integers(), y=st.just("foobar")))
def test():
  ...

Desired Behavior

@given(st.builds(MyClass, x==st.integers(), y="foobar"))
def test():
  ...

# Currently causes:
#       InvalidArgument: Expected a SearchStrategy but got mapping['y']='foobar' (type=str)
@Zac-HD
Copy link
Member

Zac-HD commented Oct 24, 2023

Yes - it complicates the interface, which is a cost that grows surprisingly quickly and is disproportionately bad for complicated use-cases.

The current workarounds with just() or functools.partial() also seem fine to me, and I think that since these are necessary tools for complex use-cases there's some value in making them the idiomatic solution in simple cases too.

@Zac-HD Zac-HD closed this as completed Oct 24, 2023
@ketozhang
Copy link
Author

Well it's a UX consideration—I can never use hypothesis without constantly going referring back to What you can generate and how. Even so what keyword do I search for to figure out it's st.just().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants