Skip to content

Commit

Permalink
Merge pull request #3788 from tybug/lowlevel-provider
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD authored Nov 19, 2023
2 parents c5efb04 + f4c221b commit 797606a
Show file tree
Hide file tree
Showing 33 changed files with 859 additions and 600 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ jobs:
pip install -r requirements/coverage.txt
pip install hypothesis-python/[all]
- name: Run tests
run: python -m pytest --numprocesses auto hypothesis-python/tests/ --ignore=hypothesis-python/tests/quality/ --ignore=hypothesis-python/tests/ghostwriter/
run: python -m pytest --numprocesses auto hypothesis-python/tests/ --ignore=hypothesis-python/tests/quality/ --ignore=hypothesis-python/tests/ghostwriter/ --ignore=hypothesis-python/tests/patching/

test-osx:
runs-on: macos-latest
Expand Down
8 changes: 8 additions & 0 deletions hypothesis-python/RELEASE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
RELEASE_TYPE: patch

This patch refactors some internals. There is no user-visible change,
but we hope to improve performance and unlock support for alternative
backends such as :pypi:`symbolic execution with crosshair <crosshair-tool>`
in future (:issue:`3086`).

Thanks to Liam DeVoe for this fantastic contribution!
11 changes: 6 additions & 5 deletions hypothesis-python/src/hypothesis/extra/_array_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from hypothesis import assume, strategies as st
from hypothesis.errors import InvalidArgument
from hypothesis.internal.conjecture import utils as cu
from hypothesis.internal.conjecture.utils import _calc_p_continue
from hypothesis.internal.coverage import check_function
from hypothesis.internal.validation import check_type, check_valid_interval
from hypothesis.strategies._internal.utils import defines_strategy
Expand Down Expand Up @@ -544,7 +544,7 @@ def _draw_core_dimensions(self, data):
if name not in dims:
dim = name.strip("?")
dims[dim] = data.draw(self.side_strat)
if self.min_dims == 0 and not data.draw_bits(3):
if self.min_dims == 0 and not data.draw_boolean(7 / 8):
dims[dim + "?"] = None
else:
dims[dim + "?"] = dims[dim]
Expand All @@ -562,6 +562,9 @@ def _draw_loop_dimensions(self, data, use=None):
assert len(use) == self.num_shapes
assert all(isinstance(x, bool) for x in use)

_gap = self.max_dims - self.min_dims
p_keep_extending_shape = _calc_p_continue(desired_avg=_gap / 2, max_size=_gap)

for dim_count in range(1, self.max_dims + 1):
dim = dim_count - 1

Expand Down Expand Up @@ -596,9 +599,7 @@ def _draw_loop_dimensions(self, data, use=None):
# shape-tuple even if it is no longer being added to.
# This helps to ensure more stable shrinking behavior.
if self.min_dims < dim_count:
use[shape_id] &= cu.biased_coin(
data, 1 - 1 / (1 + self.max_dims - dim)
)
use[shape_id] &= data.draw_boolean(p_keep_extending_shape)

if use[shape_id]:
shape.append(side)
Expand Down
2 changes: 1 addition & 1 deletion hypothesis-python/src/hypothesis/extra/array_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def do_draw(self, data):
seen = set()

while elements.more():
i = cu.integer_range(data, 0, self.array_size - 1)
i = data.draw_integer(0, self.array_size - 1)
if i in assigned:
elements.reject()
continue
Expand Down
2 changes: 1 addition & 1 deletion hypothesis-python/src/hypothesis/extra/lark.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def draw_symbol(self, data, symbol, draw_state):
data.stop_example()

def gen_ignore(self, data, draw_state):
if self.ignored_symbols and data.draw_bits(2) == 3:
if self.ignored_symbols and data.draw_boolean(1 / 4):
emit = data.draw(st.sampled_from(self.ignored_symbols))
self.draw_symbol(data, emit, draw_state)

Expand Down
2 changes: 1 addition & 1 deletion hypothesis-python/src/hypothesis/extra/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def do_draw(self, data):
seen = set()

while elements.more():
i = cu.integer_range(data, 0, self.array_size - 1)
i = data.draw_integer(0, self.array_size - 1)
if not needs_fill[i]:
elements.reject()
continue
Expand Down
Loading

0 comments on commit 797606a

Please sign in to comment.