Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request fixes #404, which I opened a few years ago to fix some performance issues related to your rejection sampling, prompted by this stackoverflow question.
Recent Hypothesis versions can usually rewrite filters expressed as
partial(operator.xxx, bound)
, and so this style is considerably more efficient in most cases. The only downside is that it can take a few minutes to get used to thepartial()
calls being "backwards", solambda x: x < y
becomespartial(op.gt, y)
(vialambda x: y > x
).In the process, I also fixed two regex-related bugs where you'd see different behavior between the first and subsequent filters:
str_matches_strategy
usedfullmatch
for the first, butmatch
for subsequent filters, allowing generation of data with a disallowed suffixstr_startswith_strategy
andstr_endswith_strategy
prepended/appended a regex boundary to the pattern. However, if the pattern includes alternation (e.g.a|b
), this boundary would only be applied to the first/last branch, and thus invalid data could be generated. Placing the user's pattern inside a group resolves this problem.Finally, I've updated the minimum Hypothesis version to that required for efficient length filtering, and included some regex expressions where the corresponding Hypothesis issue is currently open - so that they'll become efficient for your users as soon as we ship that.