diff --git a/hypothesis-python/src/hypothesis/strategies/_internal/core.py b/hypothesis-python/src/hypothesis/strategies/_internal/core.py index 8ab02d0b39..97dd2bf9b3 100644 --- a/hypothesis-python/src/hypothesis/strategies/_internal/core.py +++ b/hypothesis-python/src/hypothesis/strategies/_internal/core.py @@ -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, @@ -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 diff --git a/hypothesis-python/src/hypothesis/strategies/_internal/misc.py b/hypothesis-python/src/hypothesis/strategies/_internal/misc.py index ad37107f73..3d0b0c97e0 100644 --- a/hypothesis-python/src/hypothesis/strategies/_internal/misc.py +++ b/hypothesis-python/src/hypothesis/strategies/_internal/misc.py @@ -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()"