diff --git a/hypothesis-python/src/hypothesis/stateful.py b/hypothesis-python/src/hypothesis/stateful.py index 8f21b38b5d..acd0828a27 100644 --- a/hypothesis-python/src/hypothesis/stateful.py +++ b/hypothesis-python/src/hypothesis/stateful.py @@ -538,6 +538,7 @@ def do_draw(self, data): if not bundle: data.mark_invalid(f"Cannot draw from empty bundle {self.name!r}") + # We use both self.bundle and self.elements to make sure an index is used to safely pop self.bundle = bundle self.elements = range(len(bundle)) diff --git a/hypothesis-python/src/hypothesis/strategies/_internal/strategies.py b/hypothesis-python/src/hypothesis/strategies/_internal/strategies.py index 68bf0f1788..77ef29664d 100644 --- a/hypothesis-python/src/hypothesis/strategies/_internal/strategies.py +++ b/hypothesis-python/src/hypothesis/strategies/_internal/strategies.py @@ -556,11 +556,11 @@ def do_draw(self, data): return result def get_element(self, i): - reference = self.elements[i] - value = self._transform(self.reference_to_value(reference)) + element = self.elements[i] + value = self._transform(self.reference_to_value(element)) if is_identity_function(self.reference_to_value): return value - return reference if value is not filter_not_satisfied else filter_not_satisfied + return element if value is not filter_not_satisfied else filter_not_satisfied def do_filtered_draw(self, data): # Set of indices that have been tried so far, so that we never test