2323
2424@final
2525@dataclasses .dataclass (frozen = True )
26- class _Settings :
27- """Settings that we provide to an end user."""
26+ class Settings :
27+ """Settings for the law tests.
2828
29+ Any settings passed by the user will override the value from
30+ :func:`default_settings`.
31+ """
32+
33+ #: Settings directly passed on to `hypothesis`. We support all kwargs from
34+ #: ``@settings``, see `@settings docs
35+ #: <https://hypothesis.readthedocs.io/en/latest/settings.html>`_.
2936 settings_kwargs : dict [str , Any ]
37+ #: Whether to create examples using ``__init__`` instead of the default .
3038 use_init : bool
39+ #: Strategy for generating the container. By default, we generate examples
40+ #: of a container using:
41+ #: :func:`returns.contrib.hypothesis.containers.strategy_from_container`.
3142 container_strategy : StrategyFactory | None
43+ #: Strategies for generating values of other types. This can be useful for
44+ #: overriding ``TypeVar``, ``Callable``, etc. in case you use certain
45+ #: types that ``hypothesis`` is unable to find.
3246 other_strategies : dict [type [object ], StrategyFactory ]
3347
3448 def __post_init__ (self ) -> None :
@@ -41,7 +55,7 @@ def __post_init__(self) -> None:
4155
4256 def __or__ (self , other : Self ) -> Self :
4357 """Merge the two settings, preferring values from `other`."""
44- return _Settings (
58+ return Settings (
4559 settings_kwargs = self .settings_kwargs | other .settings_kwargs ,
4660 use_init = self .use_init | other .use_init ,
4761 container_strategy = self .container_strategy
@@ -51,7 +65,7 @@ def __or__(self, other: Self) -> Self:
5165 )
5266
5367
54- def default_settings (container_type : type [Lawful ]) -> _Settings :
68+ def default_settings (container_type : type [Lawful ]) -> Settings :
5569 """Return default settings for creating law tests.
5670
5771 We use some special strategies by default, but
@@ -68,7 +82,7 @@ def default_settings(container_type: type[Lawful]) -> _Settings:
6882 `collections.abc.Callable`. So, this is the type we should register with
6983 `hypothesis`.
7084 """
71- return _Settings (
85+ return Settings (
7286 settings_kwargs = {},
7387 use_init = False ,
7488 container_strategy = None ,
@@ -132,7 +146,7 @@ def check_all_laws(
132146 - https://mmhaskell.com/blog/2017/3/13/obey-the-type-laws
133147
134148 """
135- settings = default_settings (container_type ) | _Settings (
149+ settings = default_settings (container_type ) | Settings (
136150 settings_kwargs or {},
137151 use_init ,
138152 container_strategy ,
@@ -212,7 +226,7 @@ def _create_law_test_case(
212226 interface : type [Lawful ],
213227 law : Law ,
214228 * ,
215- settings : _Settings ,
229+ settings : Settings ,
216230) -> None :
217231 test_function = given (st .data ())(
218232 hypothesis_settings (** settings .settings_kwargs )(
@@ -248,7 +262,7 @@ def _run_law(
248262 container_type : type [Lawful ],
249263 law : Law ,
250264 * ,
251- settings : _Settings ,
265+ settings : Settings ,
252266) -> Callable [[st .DataObject ], None ]:
253267 def factory (source : st .DataObject ) -> None :
254268 with ExitStack () as stack :
@@ -265,7 +279,7 @@ def factory(source: st.DataObject) -> None:
265279
266280def _types_to_strategies (
267281 container_type : type [Lawful ],
268- settings : _Settings ,
282+ settings : Settings ,
269283) -> dict [type [object ], StrategyFactory ]:
270284 """Return a mapping from type to `hypothesis` strategy."""
271285 return settings .other_strategies | _container_mapping (
@@ -275,7 +289,7 @@ def _types_to_strategies(
275289
276290def _container_mapping (
277291 container_type : type [Lawful ],
278- settings : _Settings ,
292+ settings : Settings ,
279293) -> dict [type [object ], StrategyFactory ]:
280294 """Map `container_type` and its interfaces to the container strategy."""
281295 container_strategy = _strategy_for_container (container_type , settings )
@@ -287,7 +301,7 @@ def _container_mapping(
287301
288302def _strategy_for_container (
289303 container_type : type [Lawful ],
290- settings : _Settings ,
304+ settings : Settings ,
291305) -> StrategyFactory :
292306 return (
293307 strategy_from_container (container_type , use_init = settings .use_init )
0 commit comments