22
33from collections .abc import Callable , Iterator , Mapping
44from contextlib import contextmanager
5- from typing import TypeAlias
5+ from typing import TypeAlias , TypeVar
66
77from hypothesis import strategies as st
88from hypothesis .strategies ._internal import types # noqa: PLC2701
99
10+ Example_co = TypeVar ('Example_co' , covariant = True )
11+
1012StrategyFactory : TypeAlias = (
11- st .SearchStrategy | Callable [[type ], st .SearchStrategy ]
13+ st .SearchStrategy [Example_co ]
14+ | Callable [[type [Example_co ]], st .SearchStrategy [Example_co ]]
1215)
1316
1417
@@ -45,8 +48,8 @@ def strategies_for_types(
4548
4649
4750def look_up_strategy (
48- type_ : type [object ],
49- ) -> StrategyFactory | None :
51+ type_ : type [Example_co ],
52+ ) -> StrategyFactory [ Example_co ] | None :
5053 """Return the strategy used by `hypothesis`."""
5154 return types ._global_type_lookup .get (type_ ) # noqa: SLF001
5255
@@ -60,8 +63,8 @@ def _remove_strategy(
6063
6164
6265def apply_strategy (
63- strategy : StrategyFactory , type_ : type [object ]
64- ) -> StrategyFactory :
66+ strategy : StrategyFactory [ Example_co ] , type_ : type [Example_co ]
67+ ) -> StrategyFactory [ Example_co ] :
6568 """Apply `strategy` to `type_`."""
6669 if isinstance (strategy , st .SearchStrategy ):
6770 return strategy
0 commit comments