-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
✨ Implement Hypothesis integration #5871
Conversation
Deploying with Cloudflare Pages
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this 💖
@@ -62,6 +62,7 @@ dependencies = [ | |||
'typing-extensions>=4.5.0', | |||
'annotated-types>=0.4.0', | |||
"pydantic-core==0.33.0", | |||
"hypothesis>=6.75.3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is a dependency at all - if Hypothesis is not already imported, then it has no effect; and it's beautifully narrow in scope so that there's no downside if not.
def __iter__(self) -> Iterator[object]: # type: ignore | ||
if 'hypothesis' in sys.modules: | ||
from hypothesis import strategies as st | ||
|
||
yield st.uuids(version=self.uuid_version) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not actually an iterator, just an iterable, so the type-check error is actually correct. Try return iter([st.uuids(version=self.uuid_version)])
or return iter([])
in the different branches?
You could also annotate -> Iterator[st.SearchStrategy[UUID]]
with the import in if TYPE_CHECKING:
, to give users more-precise type annotations. I think there's enough indirection that this won't actually help in practice though.
Closing this as stale for now. Happy to reopen later if it makes sense! |
Change Summary
Implement Hypothesis integration for Pydantic v2
Related issue number
Fix #4682
Checklist
changes/<pull request or issue id>-<github username>.md
file added describing change(see changes/README.md for details)