Skip to content

Commit

Permalink
Fix container resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Jul 28, 2024
1 parent cefe4c5 commit 410e0c1
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions returns/contrib/hypothesis/_entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@
"""

from __future__ import annotations

def _setup_hook() -> None:
from typing import Sequence, Type
from typing import TYPE_CHECKING, Any, Callable, Sequence, Type, TypeVar

if TYPE_CHECKING:
from returns.primitives.laws import Lawful

_Inst = TypeVar('_Inst', bound='Lawful')


def _setup_hook() -> None:
from hypothesis import strategies as st

from returns.context import (
Expand All @@ -23,14 +30,19 @@ def _setup_hook() -> None:
from returns.future import Future, FutureResult
from returns.io import IO, IOResult
from returns.maybe import Maybe
from returns.primitives.laws import Lawful
from returns.result import Result

def factory(thing):
from returns.contrib.hypothesis.containers import (
strategy_from_container,
)
return strategy_from_container(thing)
def factory(
container_type: Type[_Inst],
) -> Callable[[Any], st.SearchStrategy[_Inst]]:
def decorator(thing: Any) -> st.SearchStrategy[_Inst]:
from returns.contrib.hypothesis.containers import (
strategy_from_container,
)
return strategy_from_container(
container_type,
)(thing)
return decorator

#: Our types that we register in hypothesis
#: to be working with ``st.from_type``
Expand All @@ -48,4 +60,4 @@ def factory(thing):
)

for type_ in registered_types:
st.register_type_strategy(type_, factory)
st.register_type_strategy(type_, factory(type_))

0 comments on commit 410e0c1

Please sign in to comment.