Skip to content

Commit

Permalink
Active fail_on_warning RTD (#614)
Browse files Browse the repository at this point in the history
* Fixes literal code blocks

We got some highlight errors when `pygments` tried to parse the code
So, we need to use the directive `:force:` and force our code to be highlighted

* Changes `doc8` config to ignore `D000` in `railway.rst`

doc8 is falling because it can't figure out what's the `:force:` directive

* Adds import for annotations from `__future__`

We need to add this import for now because `sphinx` can't figure out
how to make the forward reference. To avoid warnings about this problem
we have to import in all files that uses forward references.

* Creates `.readthedocs.yml`
  • Loading branch information
thepabloaguilar authored Sep 19, 2020
1 parent 8efb19a commit 2c18487
Show file tree
Hide file tree
Showing 28 changed files with 204 additions and 140 deletions.
12 changes: 12 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2

python:
version: 3.7
install:
- docs/requirements.txt

sphinx:
configuration: docs/conf.py
fail_on_warning: true

formats: all
2 changes: 2 additions & 0 deletions docs/pages/railway.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ inner state of containers into a regular types:
>>> assert Some(0).unwrap() == 0
.. code:: pycon
:force:
>>> Failure(1).unwrap()
Traceback (most recent call last):
Expand All @@ -160,6 +161,7 @@ use :func:`.failure <returns.interfaces.unwrappable.Unwrapable.failure>`
to unwrap the failed state:

.. code:: pycon
:force:
>>> assert Failure(1).failure() == 1
>>> Success(1).failure()
Expand Down
32 changes: 17 additions & 15 deletions returns/context/requires_context.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import (
TYPE_CHECKING,
Any,
Expand Down Expand Up @@ -87,7 +89,7 @@ class RequiresContext(
"""

#: This field has an extra 'RequiresContext' just because `mypy` needs it.
_inner_value: Callable[['RequiresContext', _EnvType], _ReturnType]
_inner_value: Callable[[RequiresContext, _EnvType], _ReturnType]

#: A convenient placeholder to call methods created by `.from_value()`:
empty: ClassVar[NoDeps] = object()
Expand Down Expand Up @@ -136,7 +138,7 @@ def __call__(self, deps: _EnvType) -> _ReturnType:

def map( # noqa: WPS125
self, function: Callable[[_ReturnType], _NewReturnType],
) -> 'RequiresContext[_NewReturnType, _EnvType]':
) -> RequiresContext[_NewReturnType, _EnvType]:
"""
Allows to compose functions inside the wrapped container.
Expand Down Expand Up @@ -164,7 +166,7 @@ def apply(
Callable[[_ReturnType], _NewReturnType],
_EnvType,
],
) -> 'RequiresContext[_NewReturnType, _EnvType]':
) -> RequiresContext[_NewReturnType, _EnvType]:
"""
Calls a wrapped function in a container on this container.
Expand All @@ -186,7 +188,7 @@ def bind(
[_ReturnType],
Kind2['RequiresContext', _NewReturnType, _EnvType],
],
) -> 'RequiresContext[_NewReturnType, _EnvType]':
) -> RequiresContext[_NewReturnType, _EnvType]:
"""
Composes a container with a function returning another container.
Expand Down Expand Up @@ -221,7 +223,7 @@ def bind(
def modify_env(
self,
function: Callable[[_NewEnvType], _EnvType],
) -> 'RequiresContext[_ReturnType, _NewEnvType]':
) -> RequiresContext[_ReturnType, _NewEnvType]:
"""
Allows to modify the environment type.
Expand All @@ -238,7 +240,7 @@ def modify_env(
return RequiresContext(lambda deps: self(function(deps)))

@classmethod
def ask(cls) -> 'RequiresContext[_EnvType, _EnvType]':
def ask(cls) -> RequiresContext[_EnvType, _EnvType]:
"""
Get current context to use the dependencies.
Expand Down Expand Up @@ -316,13 +318,13 @@ def ask(cls) -> 'RequiresContext[_EnvType, _EnvType]':
See also:
https://dev.to/gcanti/getting-started-with-fp-ts-reader-1ie5
"""
""" # noqa: F811
return RequiresContext(identity)

@classmethod
def from_value(
cls, inner_value: _FirstType,
) -> 'RequiresContext[_FirstType, NoDeps]':
) -> RequiresContext[_FirstType, NoDeps]:
"""
Used to return some specific value from the container.
Expand All @@ -343,8 +345,8 @@ def from_value(

@classmethod
def from_context(
cls, inner_value: 'RequiresContext[_NewReturnType, _NewEnvType]',
) -> 'RequiresContext[_NewReturnType, _NewEnvType]':
cls, inner_value: RequiresContext[_NewReturnType, _NewEnvType],
) -> RequiresContext[_NewReturnType, _NewEnvType]:
"""
Used to create new containers from existing ones.
Expand All @@ -363,10 +365,10 @@ def from_context(
def from_iterable(
cls,
inner_value: Iterable[
Kind2['RequiresContext', _NewReturnType, _NewEnvType],
Kind2[RequiresContext, _NewReturnType, _NewEnvType],
],
strategy: Type[BaseIterableStrategyN] = FailFast,
) -> 'RequiresContext[Sequence[_NewReturnType], _NewEnvType]':
) -> RequiresContext[Sequence[_NewReturnType], _NewEnvType]:
"""
Transforms an iterable of ``RequiresContext`` containers.
Expand All @@ -388,7 +390,7 @@ def from_iterable(
def from_requires_context_result(
cls,
inner_value: 'RequiresContextResult[_ValueType, _ErrorType, _EnvType]',
) -> 'RequiresContext[Result[_ValueType, _ErrorType], _EnvType]':
) -> RequiresContext[Result[_ValueType, _ErrorType], _EnvType]:
"""
Typecasts ``RequiresContextResult`` to ``RequiresContext`` instance.
Expand All @@ -414,7 +416,7 @@ def from_requires_context_ioresult(
cls,
inner_value:
'RequiresContextIOResult[_ValueType, _ErrorType, _EnvType]',
) -> 'RequiresContext[IOResult[_ValueType, _ErrorType], _EnvType]':
) -> RequiresContext[IOResult[_ValueType, _ErrorType], _EnvType]:
"""
Typecasts ``RequiresContextIOResult`` to ``RequiresContext`` instance.
Expand All @@ -440,7 +442,7 @@ def from_requires_context_future_result(
cls,
inner_value:
'RequiresContextFutureResult[_ValueType, _ErrorType, _EnvType]',
) -> 'RequiresContext[FutureResult[_ValueType, _ErrorType], _EnvType]':
) -> RequiresContext[FutureResult[_ValueType, _ErrorType], _EnvType]:
"""
Typecasts ``RequiresContextIOResult`` to ``RequiresContext`` instance.
Expand Down
Loading

0 comments on commit 2c18487

Please sign in to comment.