Skip to content

Commit b64c36d

Browse files
committed
lock-free validation approach
1 parent 751a089 commit b64c36d

File tree

19 files changed

+57
-26
lines changed

19 files changed

+57
-26
lines changed

hypothesis-python/RELEASE.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
RELEASE_TYPE: patch
22

33
Improve the thread-safety of strategy validation.
4+
5+
Before this release, Hypothesis did not require that ``super().__init__()`` be called in ``SearchStrategy`` subclasses. Subclassing ``SearchStrategy`` is not supported or part of the public API, but if you are subclassing it anyway, you will need to make sure to call ``super().__init__()`` after this release.

hypothesis-python/src/hypothesis/extra/_array_helpers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ def __init__(
632632
allow_newaxis,
633633
allow_fewer_indices_than_dims,
634634
):
635+
super().__init__()
635636
self.shape = shape
636637
self.min_dims = min_dims
637638
self.max_dims = max_dims

hypothesis-python/src/hypothesis/extra/array_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ class ArrayStrategy(st.SearchStrategy):
313313
def __init__(
314314
self, *, xp, api_version, elements_strategy, dtype, shape, fill, unique
315315
):
316+
super().__init__()
316317
self.xp = xp
317318
self.elements_strategy = elements_strategy
318319
self.dtype = dtype

hypothesis-python/src/hypothesis/extra/lark.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def __init__(
6868
explicit: dict[str, st.SearchStrategy[str]],
6969
alphabet: st.SearchStrategy[str],
7070
) -> None:
71+
super().__init__()
7172
assert isinstance(grammar, lark.lark.Lark)
7273
start: list[str] = grammar.options.start if start is None else [start]
7374

hypothesis-python/src/hypothesis/extra/numpy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ def compat_kw(*args, **kw):
220220

221221
class ArrayStrategy(st.SearchStrategy):
222222
def __init__(self, element_strategy, shape, dtype, fill, unique):
223+
super().__init__()
223224
self.shape = tuple(shape)
224225
self.fill = fill
225226
self.array_size = int(np.prod(shape))

hypothesis-python/src/hypothesis/stateful.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ def __hash__(self):
539539

540540
class BundleReferenceStrategy(SearchStrategy):
541541
def __init__(self, name: str, *, consume: bool = False):
542+
super().__init__()
542543
self.name = name
543544
self.consume = consume
544545

@@ -582,6 +583,7 @@ class MyStateMachine(RuleBasedStateMachine):
582583
def __init__(
583584
self, name: str, *, consume: bool = False, draw_references: bool = True
584585
) -> None:
586+
super().__init__()
585587
self.name = name
586588
self.__reference_strategy = BundleReferenceStrategy(name, consume=consume)
587589
self.draw_references = draw_references

hypothesis-python/src/hypothesis/strategies/_internal/collections.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ def __init__(
352352
*,
353353
optional: Optional[dict[Any, SearchStrategy[Any]]],
354354
):
355+
super().__init__()
355356
dict_type = type(mapping)
356357
self.mapping = mapping
357358
keys = tuple(mapping.keys())

hypothesis-python/src/hypothesis/strategies/_internal/core.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,7 @@ def __init__(
10291029
args: tuple[SearchStrategy[Any], ...],
10301030
kwargs: dict[str, SearchStrategy[Any]],
10311031
):
1032+
super().__init__()
10321033
self.target = target
10331034
self.args = args
10341035
self.kwargs = kwargs
@@ -1798,6 +1799,7 @@ def recursive(
17981799

17991800
class PermutationStrategy(SearchStrategy):
18001801
def __init__(self, values):
1802+
super().__init__()
18011803
self.values = values
18021804

18031805
def do_draw(self, data):
@@ -1828,6 +1830,7 @@ def permutations(values: Sequence[T]) -> SearchStrategy[list[T]]:
18281830

18291831
class CompositeStrategy(SearchStrategy):
18301832
def __init__(self, definition, args, kwargs):
1833+
super().__init__()
18311834
self.definition = definition
18321835
self.args = args
18331836
self.kwargs = kwargs
@@ -2173,6 +2176,7 @@ def uuids(
21732176

21742177
class RunnerStrategy(SearchStrategy):
21752178
def __init__(self, default):
2179+
super().__init__()
21762180
self.default = default
21772181

21782182
def do_draw(self, data):

hypothesis-python/src/hypothesis/strategies/_internal/datetime.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def draw_capped_multipart(
120120

121121
class DatetimeStrategy(SearchStrategy):
122122
def __init__(self, min_value, max_value, timezones_strat, allow_imaginary):
123+
super().__init__()
123124
assert isinstance(min_value, dt.datetime)
124125
assert isinstance(max_value, dt.datetime)
125126
assert min_value.tzinfo is None
@@ -219,6 +220,7 @@ def datetimes(
219220

220221
class TimeStrategy(SearchStrategy):
221222
def __init__(self, min_value, max_value, timezones_strat):
223+
super().__init__()
222224
self.min_value = min_value
223225
self.max_value = max_value
224226
self.tz_strat = timezones_strat
@@ -257,6 +259,7 @@ def times(
257259

258260
class DateStrategy(SearchStrategy):
259261
def __init__(self, min_value, max_value):
262+
super().__init__()
260263
assert isinstance(min_value, dt.date)
261264
assert isinstance(max_value, dt.date)
262265
assert min_value < max_value
@@ -320,6 +323,7 @@ def dates(
320323

321324
class TimedeltaStrategy(SearchStrategy):
322325
def __init__(self, min_value, max_value):
326+
super().__init__()
323327
assert isinstance(min_value, dt.timedelta)
324328
assert isinstance(max_value, dt.timedelta)
325329
assert min_value < max_value

hypothesis-python/src/hypothesis/strategies/_internal/numbers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
class IntegersStrategy(SearchStrategy[int]):
5252
def __init__(self, start: Optional[int], end: Optional[int]) -> None:
53+
super().__init__()
5354
assert isinstance(start, int) or start is None
5455
assert isinstance(end, int) or end is None
5556
assert start is None or end is None or start <= end

0 commit comments

Comments
 (0)