Skip to content

Commit

Permalink
Tweak weakref explanation
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Nov 19, 2022
1 parent 2bc6e4e commit 32ba8f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 7 additions & 9 deletions hypothesis-python/RELEASE.rst
@@ -1,11 +1,9 @@
RELEASE_TYPE: minor

Since :ref:`v6.27.1` the backing data structure of
:func:`~hypothesis.register_random` is a :class:`weakref.WeakKeyDictionary`. As a
consequence, passing an unreferenced object to :func:`~hypothesis.register_random` will
have no affect on Hypothesis' tracking of RNG sources. This patch modifies
:func:`~hypothesis.register_random` to raise an error when it is passed an unreferenced
object, and to emit a warning when it looks like it was passed an object that is only
referenced within a temporary scope. These checks are skipped by PyPy's interpreter.
The type annotation of :func:`~hypothesis.register_random` was also widened to permit
structural subtypes of ``random.Random``.
:func:`~hypothesis.register_random` has used :mod:`weakref` since :ref:`v6.27.1`,
allowing the :class:`~random.Random`-compatible objects to be garbage-collected when
there are no other references remaining in order to avoid memory leaks.
We now raise an error or emit a warning when this seems likely to happen immediately.

The type annotation of :func:`~hypothesis.register_random` was also widened so that
structural subtypes of :class:`~random.Random` are accepted by static typecheckers.
2 changes: 1 addition & 1 deletion hypothesis-python/docs/changes.rst
Expand Up @@ -1181,7 +1181,7 @@ This patch makes the :command:`hypothesis codemod`
-------------------

This patch changes the backing datastructures of :func:`~hypothesis.register_random`
and a few internal caches to use :class:`weakref.WeakKeyDictionary`. This reduces
and a few internal caches to use :class:`weakref.WeakValueDictionary`. This reduces
memory usage and may improve performance when registered :class:`~random.Random`
instances are only used for a subset of your tests (:issue:`3131`).

Expand Down

0 comments on commit 32ba8f9

Please sign in to comment.