13
13
import math
14
14
import warnings
15
15
from collections .abc import Iterable
16
+ from functools import cached_property
16
17
from random import Random
17
18
from sys import float_info
18
19
from time import perf_counter
@@ -413,9 +414,11 @@ class HypothesisProvider(PrimitiveProvider):
413
414
def __init__ (self , conjecturedata : Optional ["ConjectureData" ], / ):
414
415
super ().__init__ (conjecturedata )
415
416
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 )
419
422
420
423
def _maybe_draw_constant (
421
424
self ,
@@ -425,7 +428,7 @@ def _maybe_draw_constant(
425
428
p : float = 0.05 ,
426
429
) -> Optional ["ConstantT" ]:
427
430
assert self ._random is not None
428
- assert self .local_constants is not None
431
+ assert self ._local_constants is not None
429
432
assert choice_type != "boolean"
430
433
431
434
# check whether we even want a constant before spending time computing
@@ -443,7 +446,7 @@ def _maybe_draw_constant(
443
446
),
444
447
tuple (
445
448
choice
446
- for choice in self .local_constants [choice_type ]
449
+ for choice in self ._local_constants [choice_type ]
447
450
if choice_permitted (choice , constraints )
448
451
),
449
452
)
0 commit comments