diff --git a/hypothesis-python/RELEASE.rst b/hypothesis-python/RELEASE.rst new file mode 100644 index 0000000000..543590eab0 --- /dev/null +++ b/hypothesis-python/RELEASE.rst @@ -0,0 +1,5 @@ +RELEASE_TYPE: patch + +This patch fixes a rare internal error in strategies for a list of +unique items sampled from a short non-unique sequence (:issue:`2247`). +The bug was discovered via :pypi:`hypothesis-jsonschema`. diff --git a/hypothesis-python/src/hypothesis/searchstrategy/collections.py b/hypothesis-python/src/hypothesis/searchstrategy/collections.py index 7bb513addc..080e425712 100644 --- a/hypothesis-python/src/hypothesis/searchstrategy/collections.py +++ b/hypothesis-python/src/hypothesis/searchstrategy/collections.py @@ -188,7 +188,7 @@ def do_draw(self, data): remaining = LazySequenceCopy(self.element_strategy.elements) - while should_draw.more(): + while remaining and should_draw.more(): i = len(remaining) - 1 j = cu.integer_range(data, 0, i) if j != i: diff --git a/hypothesis-python/tests/cover/test_sampled_from.py b/hypothesis-python/tests/cover/test_sampled_from.py index d7e887791b..279849143c 100644 --- a/hypothesis-python/tests/cover/test_sampled_from.py +++ b/hypothesis-python/tests/cover/test_sampled_from.py @@ -92,3 +92,8 @@ def test_does_not_include_duplicates_even_when_duplicated_in_collection(ls): @given(st.lists(st.sampled_from(hrange(100)), max_size=3, unique=True)) def test_max_size_is_respected_with_unique_sampled_from(ls): assert len(ls) <= 3 + + +@given(st.lists(st.sampled_from([0, 0.0]), unique=True, min_size=1)) +def test_issue_2247_regression(ls): + assert len(ls) == 1