Skip to content

Commit

Permalink
Make utils safe to import from `hypothesis.strategies._internal.str…
Browse files Browse the repository at this point in the history
…ategies`
  • Loading branch information
Zalathar committed May 20, 2021
1 parent 06aa7b4 commit 9e82dee
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions hypothesis-python/src/hypothesis/strategies/_internal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@

import threading
from inspect import signature
from typing import Callable, Dict
from typing import TYPE_CHECKING, Callable, Dict

from hypothesis.internal.cache import LRUReusedCache
from hypothesis.internal.floats import float_to_int
from hypothesis.internal.reflection import proxies
from hypothesis.strategies._internal.lazy import LazyStrategy
from hypothesis.strategies._internal.strategies import SearchStrategy, T

_strategies: Dict[str, Callable[..., SearchStrategy]] = {}
if TYPE_CHECKING:
from hypothesis.strategies._internal.strategies import SearchStrategy, T

_strategies: Dict[str, Callable[..., "SearchStrategy"]] = {}


class FloatKey:
Expand Down Expand Up @@ -62,7 +63,9 @@ def clear_cache() -> None:
cache.clear()


def cacheable(fn: T) -> T:
def cacheable(fn: "T") -> "T":
from hypothesis.strategies._internal.strategies import SearchStrategy

@proxies(fn)
def cached_strategy(*args, **kwargs):
try:
Expand All @@ -88,7 +91,7 @@ def cached_strategy(*args, **kwargs):

def defines_strategy(
*, force_reusable_values: bool = False, try_non_lazy: bool = False
) -> Callable[[T], T]:
) -> Callable[["T"], "T"]:
"""Returns a decorator for strategy functions.
If force_reusable is True, the generated values are assumed to be
Expand All @@ -105,6 +108,8 @@ def decorator(strategy_definition):
lazily evaluated."""
_strategies[strategy_definition.__name__] = signature(strategy_definition)

from hypothesis.strategies._internal.lazy import LazyStrategy

@proxies(strategy_definition)
def accept(*args, **kwargs):
if try_non_lazy:
Expand Down

0 comments on commit 9e82dee

Please sign in to comment.