Skip to content

Commit

Permalink
Support recursive deferred
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Mar 4, 2021
1 parent b4ea7ab commit 6b9caa5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
6 changes: 6 additions & 0 deletions hypothesis-python/RELEASE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
RELEASE_TYPE: patch

This patch fixes :issue:`2794`, where nesting :func:`~hypothesis.strategies.deferred`
strategies within :func:`~hypothesis.strategies.recursive` strategies could
trigger an internal assertion. While it was always possible to get the same
results from a more sensible strategy, the convoluted form now works too.
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ def do_draw(self, data):

@contextmanager
def capped(self, max_templates):
assert not self.currently_capped
try:
was_capped = self.currently_capped
self.currently_capped = True
self.marker = max_templates
yield
finally:
self.currently_capped = False
self.currently_capped = was_capped


class RecursiveStrategy(SearchStrategy):
Expand Down
12 changes: 12 additions & 0 deletions hypothesis-python/tests/nocover/test_recursive.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,15 @@ def test(data):
thread.join()

assert not errors


SELF_REF = st.recursive(
st.deferred(lambda: st.booleans() | SELF_REF),
lambda s: st.lists(s, min_size=1),
)


@given(SELF_REF)
def test_self_ref_regression(_):
# See https://github.com/HypothesisWorks/hypothesis/issues/2794
pass

0 comments on commit 6b9caa5

Please sign in to comment.