-
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
When st.from_type() falls back to st.builds(), try passing infer for arguments with default values
#2708
Comments
I think this, and the difference between
On the other hand, However, I think it would make sense to have We would need to be careful not to break backwards compatibility by raising errors on |
st.from_type() falls back to st.builds(), try passing infer for arguments with default values
|
@Zac-HD This also has implications when registering types with contracts in Hypothesis. When you register a strategy for Is that behavior intented? |
|
Yes, the current behaviour is intended. For any registered type, |
|
@Zac-HD thanks for the clarification. I'll document that the types with contracts in constructor should always use |
This version changed the way `from_type` works in a way that caused stack overflows in the strategies for `IndividualType` and `TypeSequence` (the `Type` hierarchy is very recursive). See https://hypothesis.readthedocs.io/en/latest/changes.html#v5-46-0, HypothesisWorks/hypothesis#2708 and HypothesisWorks/hypothesis#2726 for what changed.
For functions,
buildsuses ajust(default_value)strategy for kwargs with adefault_value, but it also allows you to useinferto instead use something to the effect ofjust(default_value) | from_type(type_annotation)[1].For Pydantic models, Hypothesis inspects the
__signature__[2] and will also use the equivalent of ajust(default_value)strategy for fields with adefault_value(cf. example below). It would be nice if we could also choose to use aninfer-like strategy in this scenario. What would be the recommended workaround for that?Side question: why was the default strategy for kwargs/fields with default values chosen to be
just(default_value)instead ofjust(default_value) | from_type(type_annotation)?[1] https://hypothesis.readthedocs.io/en/latest/details.html#inferred-strategies
[2] #2388
The text was updated successfully, but these errors were encountered: