From 9c465cbb47d16fc4efc5f746cbb4ce06fa7fe66f Mon Sep 17 00:00:00 2001 From: Liam DeVoe Date: Mon, 5 Feb 2024 00:16:46 -0500 Subject: [PATCH 1/3] use data.draw_boolean in booleans() --- .../src/hypothesis/strategies/_internal/core.py | 6 +++--- .../src/hypothesis/strategies/_internal/misc.py | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) 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()" From ca6e974fe532b691cfb8ece28c284cb0a57ba4f0 Mon Sep 17 00:00:00 2001 From: Liam DeVoe Date: Mon, 5 Feb 2024 00:17:03 -0500 Subject: [PATCH 2/3] add unidiomatic explanation comment --- hypothesis-python/src/hypothesis/internal/conjecture/datatree.py | 1 + 1 file changed, 1 insertion(+) diff --git a/hypothesis-python/src/hypothesis/internal/conjecture/datatree.py b/hypothesis-python/src/hypothesis/internal/conjecture/datatree.py index 4669ca4d39..a9a6e5b196 100644 --- a/hypothesis-python/src/hypothesis/internal/conjecture/datatree.py +++ b/hypothesis-python/src/hypothesis/internal/conjecture/datatree.py @@ -242,6 +242,7 @@ def all_children(ir_type, kwargs): max_size = kwargs["max_size"] intervals = kwargs["intervals"] + # written unidiomatically in order to handle the case of max_size=inf. size = min_size while size <= max_size: for ords in itertools.product(intervals, repeat=size): From dedf8daaf0dc1a05f8017f14de3fe1f8df278deb Mon Sep 17 00:00:00 2001 From: Liam DeVoe Date: Mon, 5 Feb 2024 00:18:48 -0500 Subject: [PATCH 3/3] add release notes --- hypothesis-python/RELEASE.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 hypothesis-python/RELEASE.rst diff --git a/hypothesis-python/RELEASE.rst b/hypothesis-python/RELEASE.rst new file mode 100644 index 0000000000..ee54f8bbf9 --- /dev/null +++ b/hypothesis-python/RELEASE.rst @@ -0,0 +1,3 @@ +RELEASE_TYPE: patch + +This patch refactors some internals. There is no user-visible change.