From fd1b90a6c3aee0e3e96b5e04c44b7150dce920fc Mon Sep 17 00:00:00 2001 From: Ryan Soklaski Date: Fri, 18 Nov 2022 17:01:29 -0500 Subject: [PATCH] Mention pypy in docs and consolidate code blocks --- .../src/hypothesis/internal/entropy.py | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/hypothesis-python/src/hypothesis/internal/entropy.py b/hypothesis-python/src/hypothesis/internal/entropy.py index 7b4880b313..d477477924 100644 --- a/hypothesis-python/src/hypothesis/internal/entropy.py +++ b/hypothesis-python/src/hypothesis/internal/entropy.py @@ -91,34 +91,26 @@ def register_random(r: RandomLike) -> None: `_ to ``r``, thus ``r`` will only be managed by Hypothesis as long as it has active references elsewhere at runtime. The pattern ``register_random(MyRandom())`` - will raise a ``ReferenceError`` to help protect users from this issue. That - being said, a pattern like + will raise a ``ReferenceError`` to help protect users from this issue. + This check does not occur for the PyPy interpreter. See the following example for + an illustration of this issue .. code-block:: python - # contents of mylib/foo.py + def my_BROKEN_hook(): + r = MyRandomLike() - def my_hook(): - rng = MyRandomSingleton() - register_random(rng) - return None - - must be refactored as + # `r` will be garbage collected after the hook resolved + # and Hypothesis will 'forget' that it was registered + register_random(r) # Hypothesis will emit a warning - .. code-block:: python - # contents of mylib/foo.py + rng = MyRandomLike() - rng = MyRandomSingleton() - - def my_hook(): + def my_WORKING_hook(): register_random(rng) - return None - - in order for Hypothesis to continue managing the random instance after the hook - is called. """ if not (hasattr(r, "seed") and hasattr(r, "getstate") and hasattr(r, "setstate")): raise InvalidArgument(f"r={r!r} does not have all the required methods")