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

✨ Implement Hypothesis integration #5871

Closed
wants to merge 1 commit into from

Conversation

lig
Copy link
Contributor

@lig lig commented May 25, 2023

Change Summary

Implement Hypothesis integration for Pydantic v2

Related issue number

Fix #4682

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • changes/<pull request or issue id>-<github username>.md file added describing change
    (see changes/README.md for details)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

@cloudflare-pages
Copy link

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 16d5c24
Status: ✅  Deploy successful!
Preview URL: https://0c247841.pydantic-docs2.pages.dev
Branch Preview URL: https://4682-v2-hypothesis-plugin-re.pydantic-docs2.pages.dev

View logs

@samuelcolvin samuelcolvin added the deferred deferred until future release or until something else gets done label May 28, 2023
Copy link
Contributor

@Zac-HD Zac-HD left a 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",
Copy link
Contributor

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.

Comment on lines +364 to +368
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)
Copy link
Contributor

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.

@sydney-runkle
Copy link
Member

Closing this as stale for now. Happy to reopen later if it makes sense!

@samuelcolvin samuelcolvin deleted the 4682-v2-hypothesis-plugin-rewrite branch May 1, 2024 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deferred deferred until future release or until something else gets done
Projects
None yet
Development

Successfully merging this pull request may close these issues.

V2: hypothesis plugin rewrite
4 participants