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
Make sampled_from()
non-lazy
#2515
Conversation
2e9b797
to
22c5fbe
Compare
hypothesis-python/src/hypothesis/strategies/_internal/strategies.py
Outdated
Show resolved
Hide resolved
OK, I think that's done now 🙂 |
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've added some comments as thoughts for later, but I'll open a ticket about them as they're unrelated to this PR.
@@ -191,12 +191,18 @@ def cached_strategy(*args, **kwargs): | |||
return cached_strategy | |||
|
|||
|
|||
def base_defines_strategy(force_reusable: bool) -> Callable[[T], T]: | |||
def base_defines_strategy( | |||
force_reusable: bool, *, try_non_lazy: bool = False |
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.
No need to do this as part of this pull request, but maybe we should open a minor ticket to move this over to keyword only arguments for both.
@@ -220,6 +236,7 @@ def accept(*args, **kwargs): | |||
|
|||
defines_strategy = base_defines_strategy(False) | |||
defines_strategy_with_reusable_values = base_defines_strategy(True) | |||
defines_strategy_without_laziness = base_defines_strategy(False, try_non_lazy=True) |
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.
Also no need to do this in this PR but I kinda feel like we should just inline all of these.
Closes #2507. This is kinda fiddly, but not as bad as I expected... all we really lose is the "repr preserves sequence type" thing and there's no good way to do that without storing a shallow copy of whatever we're sampling just for the repr.