Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
hooks:
- id: actionlint
- repo: https://github.com/woodruffw/zizmor-pre-commit
rev: v1.26.1
rev: v1.27.0
hooks:
- id: zizmor
args: ["--no-progress", "--fix"]
Expand All @@ -19,7 +19,7 @@ repos:
hooks:
- id: shellcheck
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.21
rev: v0.15.22
hooks:
- id: ruff
args: ["--exit-non-zero-on-fix"]
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def _get_project_meta():

pkg_meta = _get_project_meta()
project = str(pkg_meta['name'])
copyright = '2019, dry-python team' # noqa: A001
copyright = '2019, dry-python team' # ruff:ignore[builtin-variable-shadowing]
author = 'dry-python team'

# The short X.Y version
Expand Down
8 changes: 4 additions & 4 deletions returns/_internal/futures/_future.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ async def async_apply(
inner_value: Awaitable[_ValueType_co],
) -> _NewValueType:
"""Async applies a container with function over a value."""
return (await container)._inner_value(await inner_value) # noqa: SLF001
return (await container)._inner_value(await inner_value) # ruff:ignore[private-member-access]


async def async_bind(
function: Callable[[_ValueType_co], Kind1['Future', _NewValueType]],
inner_value: Awaitable[_ValueType_co],
) -> _NewValueType:
"""Async binds a container over a value."""
return (await dekind(function(await inner_value)))._inner_value # noqa: SLF001
return (await dekind(function(await inner_value)))._inner_value # ruff:ignore[private-member-access]


async def async_bind_awaitable(
Expand All @@ -51,7 +51,7 @@ async def async_bind_async(
inner_value: Awaitable[_ValueType_co],
) -> _NewValueType:
"""Async binds a coroutine with container over a value."""
inner_io = dekind(await function(await inner_value))._inner_value # noqa: SLF001
inner_io = dekind(await function(await inner_value))._inner_value # ruff:ignore[private-member-access]
return await inner_io


Expand All @@ -60,4 +60,4 @@ async def async_bind_io(
inner_value: Awaitable[_ValueType_co],
) -> _NewValueType:
"""Async binds a container over a value."""
return function(await inner_value)._inner_value # noqa: SLF001
return function(await inner_value)._inner_value # ruff:ignore[private-member-access]
18 changes: 9 additions & 9 deletions returns/_internal/futures/_future_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def async_apply(
inner_value: Awaitable[Result[_ValueType_co, _ErrorType_co]],
) -> Result[_NewValueType, _ErrorType_co]:
"""Async maps a function over a value."""
return (await inner_value).apply((await container)._inner_value) # noqa: SLF001
return (await inner_value).apply((await container)._inner_value) # ruff:ignore[private-member-access]


async def async_bind(
Expand All @@ -52,7 +52,7 @@ async def async_bind(
"""Async binds a container over a value."""
container = await inner_value
if isinstance(container, Success):
return (await dekind(function(container.unwrap())))._inner_value # noqa: SLF001
return (await dekind(function(container.unwrap())))._inner_value # ruff:ignore[private-member-access]
return container # type: ignore[return-value]


Expand All @@ -77,7 +77,7 @@ async def async_bind_async(
"""Async binds a coroutine with container over a value."""
container = await inner_value
if isinstance(container, Success):
return await dekind(await function(container.unwrap()))._inner_value # noqa: SLF001
return await dekind(await function(container.unwrap()))._inner_value # ruff:ignore[private-member-access]
return container # type: ignore[return-value]


Expand All @@ -96,7 +96,7 @@ async def async_bind_ioresult(
"""Async binds a container returning ``IOResult`` over a value."""
container = await inner_value
if isinstance(container, Success):
return function(container.unwrap())._inner_value # noqa: SLF001
return function(container.unwrap())._inner_value # ruff:ignore[private-member-access]
return container # type: ignore[return-value]


Expand All @@ -107,7 +107,7 @@ async def async_bind_io(
"""Async binds a container returning ``IO`` over a value."""
container = await inner_value
if isinstance(container, Success):
return Success(function(container.unwrap())._inner_value) # noqa: SLF001
return Success(function(container.unwrap())._inner_value) # ruff:ignore[private-member-access]
return container # type: ignore[return-value]


Expand Down Expand Up @@ -155,21 +155,21 @@ async def async_lash(
container = await inner_value
if isinstance(container, Success):
return container
return (await dekind(function(container.failure())))._inner_value # noqa: SLF001
return (await dekind(function(container.failure())))._inner_value # ruff:ignore[private-member-access]


async def async_from_success(
container: Future[_NewValueType],
) -> Result[_NewValueType, Any]:
"""Async success unit factory."""
return Success((await container)._inner_value) # noqa: SLF001
return Success((await container)._inner_value) # ruff:ignore[private-member-access]


async def async_from_failure(
container: Future[_NewErrorType],
) -> Result[Any, _NewErrorType]:
"""Async failure unit factory."""
return Failure((await container)._inner_value) # noqa: SLF001
return Failure((await container)._inner_value) # ruff:ignore[private-member-access]


async def async_compose_result(
Expand All @@ -180,4 +180,4 @@ async def async_compose_result(
inner_value: Awaitable[Result[_ValueType_co, _ErrorType_co]],
) -> Result[_NewValueType, _ErrorType_co]:
"""Async composes ``Result`` based function."""
return (await dekind(function(await inner_value)))._inner_value # noqa: SLF001
return (await dekind(function(await inner_value)))._inner_value # ruff:ignore[private-member-access]
8 changes: 4 additions & 4 deletions returns/_internal/futures/_reader_future_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ async def async_bind_async(
deps: _EnvType,
) -> Result[_NewValueType, _ErrorType_co]:
"""Async binds a coroutine with container over a value."""
inner_value = await container(deps)._inner_value # noqa: SLF001
inner_value = await container(deps)._inner_value # ruff:ignore[private-member-access]
if isinstance(inner_value, Success):
return await dekind( # noqa: SLF001
return await dekind( # ruff:ignore[private-member-access]
await function(inner_value.unwrap()),
)(deps)._inner_value
return inner_value # type: ignore[return-value]
Expand All @@ -57,5 +57,5 @@ async def async_compose_result(
deps: _EnvType,
) -> Result[_NewValueType, _ErrorType_co]:
"""Async composes ``Result`` based function."""
new_container = dekind(function((await container(deps))._inner_value)) # noqa: SLF001
return (await new_container(deps))._inner_value # noqa: SLF001
new_container = dekind(function((await container(deps))._inner_value)) # ruff:ignore[private-member-access]
return (await new_container(deps))._inner_value # ruff:ignore[private-member-access]
2 changes: 1 addition & 1 deletion returns/context/requires_context_ioresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ def compose_result(
"""
return RequiresContextIOResult(
lambda deps: dekind(
function(self(deps)._inner_value), # noqa: SLF001
function(self(deps)._inner_value), # ruff:ignore[private-member-access]
)(deps),
)

Expand Down
19 changes: 12 additions & 7 deletions returns/contrib/hypothesis/_entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,29 @@


def _setup_hook() -> None:
from hypothesis import strategies as st # noqa: PLC0415
from hypothesis import (
strategies as st,
)

from returns.context import ( # noqa: PLC0415
from returns.context import ( # ruff:ignore[import-outside-top-level]
RequiresContext,
RequiresContextFutureResult,
RequiresContextIOResult,
RequiresContextResult,
)
from returns.future import Future, FutureResult # noqa: PLC0415
from returns.io import IO, IOResult # noqa: PLC0415
from returns.maybe import Maybe # noqa: PLC0415
from returns.result import Result # noqa: PLC0415
from returns.future import ( # ruff:ignore[import-outside-top-level]
Future,
FutureResult,
)
from returns.io import IO, IOResult # ruff:ignore[import-outside-top-level]
from returns.maybe import Maybe # ruff:ignore[import-outside-top-level]
from returns.result import Result # ruff:ignore[import-outside-top-level]

def factory(
container_type: type[_Inst],
) -> Callable[[Any], st.SearchStrategy[_Inst]]:
def decorator(thing: Any) -> st.SearchStrategy[_Inst]:
from returns.contrib.hypothesis.containers import ( # noqa: PLC0415
from returns.contrib.hypothesis.containers import ( # ruff:ignore[import-outside-top-level]
strategy_from_container,
)

Expand Down
9 changes: 7 additions & 2 deletions returns/contrib/hypothesis/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ def strategy_from_container(
will produce any value for success cases
and only exceptions for failure cases.
"""
from returns.interfaces.applicative import ApplicativeN # noqa: PLC0415
from returns.interfaces.specific import maybe, result # noqa: PLC0415
from returns.interfaces.applicative import (
ApplicativeN,
)
from returns.interfaces.specific import ( # ruff:ignore[import-outside-top-level]
maybe,
result,
)

def factory(type_: type) -> st.SearchStrategy:
value_type, error_type = _get_type_vars(type_)
Expand Down
10 changes: 6 additions & 4 deletions returns/contrib/hypothesis/laws.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
from hypothesis import given
from hypothesis import settings as hypothesis_settings
from hypothesis import strategies as st
from hypothesis.strategies._internal import types # noqa: PLC2701
from hypothesis.strategies._internal import (
types,
)

from returns.contrib.hypothesis.containers import strategy_from_container
from returns.contrib.hypothesis.type_resolver import (
Expand Down Expand Up @@ -205,15 +207,15 @@ def clean_plugin_context() -> Iterator[None]:
Otherwise, some types might be messed up.
"""
saved_stategies = {}
for strategy_key, strategy in types._global_type_lookup.items(): # noqa: SLF001
for strategy_key, strategy in types._global_type_lookup.items(): # ruff:ignore[private-member-access]
if isinstance( # type: ignore[redundant-expr, unused-ignore]
strategy_key,
type,
) and strategy_key.__module__.startswith('returns.'):
saved_stategies.update({strategy_key: strategy})

for key_to_remove in saved_stategies:
types._global_type_lookup.pop(key_to_remove) # noqa: SLF001
types._global_type_lookup.pop(key_to_remove) # ruff:ignore[private-member-access]
_clean_caches()

try:
Expand All @@ -224,7 +226,7 @@ def clean_plugin_context() -> Iterator[None]:


def _clean_caches() -> None:
st.from_type.__clear_cache() # type: ignore[attr-defined] # noqa: SLF001
st.from_type.__clear_cache() # type: ignore[attr-defined] # ruff:ignore[private-member-access]


def _create_law_test_case(
Expand Down
10 changes: 6 additions & 4 deletions returns/contrib/hypothesis/type_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from typing import TypeAlias, TypeVar

from hypothesis import strategies as st
from hypothesis.strategies._internal import types # noqa: PLC2701
from hypothesis.strategies._internal import (
types,
)

Example_co = TypeVar('Example_co', covariant=True)

Expand Down Expand Up @@ -51,14 +53,14 @@ def look_up_strategy(
type_: type[Example_co],
) -> StrategyFactory[Example_co] | None:
"""Return the strategy used by `hypothesis`."""
return types._global_type_lookup.get(type_) # noqa: SLF001
return types._global_type_lookup.get(type_) # ruff:ignore[private-member-access]


def _remove_strategy(
type_: type[object],
) -> None:
"""Remove the strategy registered for `type_`."""
types._global_type_lookup.pop(type_) # noqa: SLF001
types._global_type_lookup.pop(type_) # ruff:ignore[private-member-access]
_clean_caches()


Expand All @@ -72,4 +74,4 @@ def apply_strategy(


def _clean_caches() -> None:
st.from_type.__clear_cache() # type: ignore[attr-defined] # noqa: SLF001
st.from_type.__clear_cache() # type: ignore[attr-defined] # ruff:ignore[private-member-access]
20 changes: 15 additions & 5 deletions returns/contrib/pytest/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def assert_equal( # noqa: WPS602
backend: str = 'asyncio',
) -> None:
"""Can compare two containers even with extra calling and awaiting."""
from returns.primitives.asserts import assert_equal # noqa: PLC0415
from returns.primitives.asserts import (
assert_equal,
)

assert_equal(first, second, deps=deps, backend=backend)

Expand Down Expand Up @@ -153,14 +155,22 @@ def _spy_error_handling() -> Iterator[_ErrorsHandled]:

# delayed imports are needed to prevent messing up coverage
def _containers_to_patch() -> list:
from returns.context import ( # noqa: PLC0415
from returns.context import ( # ruff:ignore[import-outside-top-level]
RequiresContextFutureResult,
RequiresContextIOResult,
RequiresContextResult,
)
from returns.future import FutureResult # noqa: PLC0415
from returns.io import IOFailure, IOSuccess # noqa: PLC0415
from returns.result import Failure, Success # noqa: PLC0415
from returns.future import (
FutureResult,
)
from returns.io import ( # ruff:ignore[import-outside-top-level]
IOFailure,
IOSuccess,
)
from returns.result import ( # ruff:ignore[import-outside-top-level]
Failure,
Success,
)

return [
Success,
Expand Down
Loading