Skip to content

Commit

Permalink
Support non-weakrefable types
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Jul 3, 2022
1 parent 290f04d commit ef8bf10
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions hypothesis-python/RELEASE.rst
@@ -0,0 +1,4 @@
RELEASE_TYPE: patch

:func:`hypothesis.event` now works for hashable objects which do not
support weakrefs, such as integers and tuples.
Expand Up @@ -1067,10 +1067,13 @@ def event_to_string(self, event):
return event
try:
return self.events_to_strings[event]
except KeyError:
except (KeyError, TypeError):
pass
result = str(event)
self.events_to_strings[event] = result
try:
self.events_to_strings[event] = result
except TypeError:
pass
return result


Expand Down
5 changes: 5 additions & 0 deletions hypothesis-python/tests/conjecture/test_engine.py
Expand Up @@ -1587,3 +1587,8 @@ def test(data):
runner.cached_test_function([c])

assert runner.tree.is_exhausted


def test_can_convert_non_weakref_types_to_event_strings():
runner = ConjectureRunner(lambda data: None)
runner.event_to_string(())
5 changes: 5 additions & 0 deletions hypothesis-python/tests/cover/test_statistical_events.py
Expand Up @@ -254,3 +254,8 @@ def test(value):
stats = describe_statistics(call_for_statistics(test))
assert "- Events:" in stats
assert "- Highest target score: " in stats


@given(st.booleans())
def test_event_with_non_weakrefable_keys(b):
event((b,))

0 comments on commit ef8bf10

Please sign in to comment.