Skip to content

Allow strategy-generating functions to not provide strategies#3769

Merged
Zac-HD merged 7 commits intoHypothesisWorks:masterfrom
h4l:optional-strategy-function
Oct 15, 2023
Merged

Allow strategy-generating functions to not provide strategies#3769
Zac-HD merged 7 commits intoHypothesisWorks:masterfrom
h4l:optional-strategy-function

Conversation

@h4l
Copy link
Copy Markdown
Contributor

@h4l h4l commented Oct 15, 2023

This PR implements the feature discussed in #3767, to allow strategy-generating functions registered with register_type_strategy() to choose not to provide a strategy for a type by returning NotImplemented
instead of a strategy.

This doesn't directly fix issue #3767 (PR #3768 is the fix) but this feature would allow a strategy to not trigger the issue, and is also useful in its own right, to limit when a globally-registered type strategy is used. For example, to only provide a custom strategy for certain super-types of a type, or certain generic parameters, while deferring to another strategy for the unhandled cases.

@h4l h4l force-pushed the optional-strategy-function branch from 273a103 to 43a2cdf Compare October 15, 2023 08:23
@h4l

This comment was marked as resolved.

h4l and others added 7 commits October 15, 2023 14:39
test_self_ref_regression is failing randomly with FailedHealthCheck for
too slow and filtering too much. We now suppress these health checks for
this test.
Custom type strategies registered with register_type_strategy() can now
choose not to provide a strategy for a type by returning NotImplemented
instead of a strategy.

This allows custom strategies to only provide a custom strategies for
certain subtypes of a type, or certain generic parameters, while
deferring to another strategy for the unhandled cases.
@Zac-HD Zac-HD enabled auto-merge October 15, 2023 21:10
This was referenced Oct 15, 2023
@Zac-HD Zac-HD force-pushed the optional-strategy-function branch 2 times, most recently from 7ba34d5 to aad4098 Compare October 15, 2023 21:19
@Zac-HD Zac-HD merged commit 56af52a into HypothesisWorks:master Oct 15, 2023
@h4l h4l deleted the optional-strategy-function branch October 16, 2023 04:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants