Skip to content

Commit

Permalink
reduce more internal examples
Browse files Browse the repository at this point in the history
  • Loading branch information
tybug committed Jun 13, 2024
1 parent e406b78 commit 9457c1b
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions hypothesis-python/src/hypothesis/internal/conjecture/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ def sample(
forced: Optional[int] = None,
fake_forced: bool = False,
) -> int:
data.start_example(SAMPLE_IN_SAMPLER_LABEL)
if self.observe:
data.start_example(SAMPLE_IN_SAMPLER_LABEL)
forced_choice = ( # pragma: no branch # https://github.com/nedbat/coveragepy/issues/1617
None
if forced is None
Expand Down Expand Up @@ -203,7 +204,8 @@ def sample(
fake_forced=fake_forced,
observe=self.observe,
)
data.stop_example()
if self.observe:
data.stop_example()
if use_alternate:
assert forced is None or alternate == forced, (forced, alternate)
return alternate
Expand Down Expand Up @@ -254,15 +256,23 @@ def __init__(
self.rejected = False
self.observe = observe

def stop_example(self):
if self.observe:
self.data.stop_example()

def start_example(self, label):
if self.observe:
self.data.start_example(label)

def more(self) -> bool:
"""Should I draw another element to add to the collection?"""
if self.drawn:
self.data.stop_example()
self.stop_example()

self.drawn = True
self.rejected = False

self.data.start_example(ONE_FROM_MANY_LABEL)
self.start_example(ONE_FROM_MANY_LABEL)
if self.min_size == self.max_size:
# if we have to hit an exact size, draw unconditionally until that
# point, and no further.
Expand Down Expand Up @@ -291,7 +301,7 @@ def more(self) -> bool:
self.count += 1
return True
else:
self.data.stop_example()
self.stop_example()
return False

def reject(self, why: Optional[str] = None) -> None:
Expand Down

0 comments on commit 9457c1b

Please sign in to comment.