Skip to content

Commit 05b5d6c

Browse files
committed
defer local_constants instantiation
1 parent 4ec6b01 commit 05b5d6c

File tree

1 file changed

+8
-5
lines changed
  • hypothesis-python/src/hypothesis/internal/conjecture

1 file changed

+8
-5
lines changed

hypothesis-python/src/hypothesis/internal/conjecture/providers.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import math
1414
import warnings
1515
from collections.abc import Iterable
16+
from functools import cached_property
1617
from random import Random
1718
from sys import float_info
1819
from time import perf_counter
@@ -413,9 +414,11 @@ class HypothesisProvider(PrimitiveProvider):
413414
def __init__(self, conjecturedata: Optional["ConjectureData"], /):
414415
super().__init__(conjecturedata)
415416
self._random = None if self._cd is None else self._cd._random
416-
self.local_constants = (
417-
None if self._random is None else _get_local_constants(self._random)
418-
)
417+
418+
@cached_property
419+
def _local_constants(self):
420+
assert self._random is not None
421+
return _get_local_constants(self._random)
419422

420423
def _maybe_draw_constant(
421424
self,
@@ -425,7 +428,7 @@ def _maybe_draw_constant(
425428
p: float = 0.05,
426429
) -> Optional["ConstantT"]:
427430
assert self._random is not None
428-
assert self.local_constants is not None
431+
assert self._local_constants is not None
429432
assert choice_type != "boolean"
430433

431434
# check whether we even want a constant before spending time computing
@@ -443,7 +446,7 @@ def _maybe_draw_constant(
443446
),
444447
tuple(
445448
choice
446-
for choice in self.local_constants[choice_type]
449+
for choice in self._local_constants[choice_type]
447450
if choice_permitted(choice, constraints)
448451
),
449452
)

0 commit comments

Comments
 (0)