-
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
Registering strategies for parametrised generic types behaves differently for pydantic.generics.GenericModel #2940
Comments
|
Thanks for reporting this - I'm sure we can fix it with some more tricky introspection 😅 And FYI the two strategies below are equivalent; the latter idiom is often easier to read. st.lists(st.booleans()).map(lambda x: MyCollection(items=x))
st.builds(MyCollection, items=st.lists(st.booleans())) |
|
I've looked into this at some length, and I don't think we actually can support it 😕
Possible solutions, from best to worst:
|
|
Thanks for looking into this @Zac-HD. Would it be reasonable to ask Pydantic to inherit from |
|
Yeah, I think that would make sense for generic types - and there's a decent chance that it would be pretty easy to implement too 🙂 |
The Hypothesis docs say that you may not register type strategies for parametrised generic types such as
MyCollection[int][1]. As expected, we see an error when trying this out:However, the behaviour is different and surprising when using Pydantic
GenericModels. Specifically:lambda T: ...strategy forMyCollection.MyCollection[T].[1] https://hypothesis.readthedocs.io/en/latest/data.html#hypothesis.strategies.register_type_strategy
The text was updated successfully, but these errors were encountered: