From ccf19f93af7a150c808ecf86ec31ba0f0d74494b Mon Sep 17 00:00:00 2001 From: sobolevn Date: Fri, 14 Mar 2025 18:03:14 +0300 Subject: [PATCH 1/2] Fix rtd --- .readthedocs.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 18a3aca15..c1febf763 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -4,7 +4,7 @@ version: 2 # Set the version of Python and other tools you might need build: os: ubuntu-lts-latest - tools: {python: "3.11"} + tools: {python: "3.12"} jobs: pre_create_environment: - asdf plugin add poetry @@ -12,7 +12,11 @@ build: - asdf global poetry latest - poetry config virtualenvs.create false - poetry self add poetry-plugin-export - - poetry export --only main --only docs --extras check_laws --format=requirements.txt --output=requirements.txt + - poetry export + --only main --only docs + --extras check_laws --extras compatible_mypy + --format=requirements.txt + --output=requirements.txt python: install: From cc5670b0263971caa9e857e5e9464c74478af6a4 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Fri, 14 Mar 2025 18:09:32 +0300 Subject: [PATCH 2/2] Fix rtd --- docs/pages/contrib/hypothesis_plugins.rst | 3 ++- returns/contrib/hypothesis/laws.py | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/docs/pages/contrib/hypothesis_plugins.rst b/docs/pages/contrib/hypothesis_plugins.rst index b979cc178..81d134e57 100644 --- a/docs/pages/contrib/hypothesis_plugins.rst +++ b/docs/pages/contrib/hypothesis_plugins.rst @@ -108,7 +108,8 @@ like ``Future``, ``ReaderFutureResult``, etc that have complex ``__init__`` signatures. And we don't want to mess with them. -Warning:: +.. warning:: + Checking laws is not compatible with ``pytest-xdist``, because we use a lot of global mutable state there. Please, use ``returns_lawful`` marker diff --git a/returns/contrib/hypothesis/laws.py b/returns/contrib/hypothesis/laws.py index feb59fec7..48c9ea499 100644 --- a/returns/contrib/hypothesis/laws.py +++ b/returns/contrib/hypothesis/laws.py @@ -24,7 +24,8 @@ @final @dataclasses.dataclass(frozen=True) class Settings: - """Settings for the law tests. + """ + Settings for the law tests. This sets the context for each generated law test, by temporarily registering strategies for various types and passing any ``hypothesis`` @@ -76,11 +77,11 @@ def default_settings(container_type: type[Lawful]) -> Settings: We use some special strategies by default, but they can be overridden by the user if needed: - + `TypeVar`: We need to make sure that the values generated behave - sensibly when tested for equality. + - ``TypeVar``: We need to make sure that the values generated behave + sensibly when tested for equality. - + `collections.abc.Callable`: We need to generate pure functions, which - are not the default. + - ``collections.abc.Callable``: We need to generate pure functions, + which are not the default. Note that this is `collections.abc.Callable`, NOT `typing.Callable`. This is because, at runtime, `typing.get_origin(Callable[[int], str])` is @@ -186,10 +187,11 @@ def pure_functions_factory(thing) -> st.SearchStrategy: def type_vars_factory(thing: type[object]) -> StrategyFactory: - """Strategy factory for ``TypeVar``s. + """ + Strategy factory for ``TypeVar`` objects. - We ensure that values inside strategies are self-equal. For example, - ``nan`` does not work for us. + We ensure that values inside strategies are self-equal. + For example, ``float('nan')`` does not work for us. """ return types.resolve_TypeVar(thing).filter( # type: ignore[no-any-return] lambda inner: inner == inner, # noqa: PLR0124, WPS312