Skip to content

Commit

Permalink
Wrap differently?
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Jul 4, 2022
1 parent 0d27b41 commit f96679a
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions hypothesis-python/src/hypothesis/strategies/_internal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
Protocol = object # type: ignore[assignment]

try:
from typing import Concatenate, ParamSpec
from typing import Concatenate, ParamSpec # type: ignore
except ImportError:
try:
from typing_extensions import Concatenate, ParamSpec
Expand Down Expand Up @@ -1515,18 +1515,8 @@ def __call__(self, strategy: SearchStrategy[Ex], label: object = None) -> Ex:
raise NotImplementedError


@cacheable
def composite(f: Callable[..., Ex]) -> Callable[..., SearchStrategy[Ex]]:
"""Defines a strategy that is built out of potentially arbitrarily many
other strategies.
This is intended to be used as a decorator. See
:ref:`the full documentation for more details <composite-strategies>`
about how to use this function.
Examples from this strategy shrink by shrinking the output of each draw
call.
"""
def _composite(f):
# Wrapped below, using ParamSpec if available
if isinstance(f, (classmethod, staticmethod)):
special_method = type(f)
f = f.__func__
Expand Down Expand Up @@ -1566,11 +1556,36 @@ def accept(*args, **kwargs):

if typing.TYPE_CHECKING or ParamSpec is not None:
P = ParamSpec("P")
_composite = composite

def composite(
f: Callable[Concatenate[DrawFn, P], Ex]
) -> Callable[P, SearchStrategy[Ex]]:
"""Defines a strategy that is built out of potentially arbitrarily many
other strategies.
This is intended to be used as a decorator. See
:ref:`the full documentation for more details <composite-strategies>`
about how to use this function.
Examples from this strategy shrink by shrinking the output of each draw
call.
"""
return _composite(f)

else:

@cacheable
def composite(f: Callable[..., Ex]) -> Callable[..., SearchStrategy[Ex]]:
"""Defines a strategy that is built out of potentially arbitrarily many
other strategies.
This is intended to be used as a decorator. See
:ref:`the full documentation for more details <composite-strategies>`
about how to use this function.
Examples from this strategy shrink by shrinking the output of each draw
call.
"""
return _composite(f)


Expand Down

0 comments on commit f96679a

Please sign in to comment.