Skip to content

Commit

Permalink
use data.draw_boolean in booleans()
Browse files Browse the repository at this point in the history
  • Loading branch information
tybug committed Feb 5, 2024
1 parent 5ec646c commit 9c465cb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions hypothesis-python/src/hypothesis/strategies/_internal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
from hypothesis.strategies._internal.deferred import DeferredStrategy
from hypothesis.strategies._internal.functions import FunctionStrategy
from hypothesis.strategies._internal.lazy import LazyStrategy, unwrap_strategies
from hypothesis.strategies._internal.misc import just, none, nothing
from hypothesis.strategies._internal.misc import BooleansStrategy, just, none, nothing
from hypothesis.strategies._internal.numbers import (
IntegersStrategy,
Real,
Expand Down Expand Up @@ -158,14 +158,14 @@


@cacheable
@defines_strategy()
@defines_strategy(force_reusable_values=True)
def booleans() -> SearchStrategy[bool]:
"""Returns a strategy which generates instances of :class:`python:bool`.
Examples from this strategy will shrink towards ``False`` (i.e.
shrinking will replace ``True`` with ``False`` where possible).
"""
return SampledFromStrategy([False, True], repr_="booleans()")
return BooleansStrategy()


@overload
Expand Down
8 changes: 8 additions & 0 deletions hypothesis-python/src/hypothesis/strategies/_internal/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,11 @@ def nothing() -> SearchStrategy:
Examples from this strategy do not shrink (because there are none).
"""
return NOTHING


class BooleansStrategy(SearchStrategy):
def do_draw(self, data):
return data.draw_boolean()

def __repr__(self):
return "booleans()"

0 comments on commit 9c465cb

Please sign in to comment.