id
int64
0
190k
prompt
stringlengths
21
13.4M
docstring
stringlengths
1
12k
146,287
import multiprocessing from urllib import parse from main import output from main import request from main import yaml def POC_select(poc,filenames): if poc not in filenames and poc !="None": flag="6" output.exception(flag) return if poc == "None": return True return False
null
146,288
import multiprocessing from urllib import parse from main import output from main import request from main import yaml def Type_deal(value, type): if type=="file": #处理文件 result=[] try: with open(value,'r',encoding ="utf-8") as file_object: lines = file_object.r...
null
146,289
def load(url): print( ''' \033[34m[*]\033[0m 正在检测:{} 请稍等...........'''.format(url))
null
146,290
import time from os import system def index(): print(''' ██████╗ █████╗ ███████╗ ██╗ ██╗ ██████╗ ████████╗ ██████╗ ██████╗ ██╗ ██╝ ██╗ ██╔══██╗ ██╔════╝ ╚██╗██╔╝ ██╔══██╗╚══██╔══╝██╝ ██╗ ██╝ ██║ ██║ ██ ██║ ███████║ █████╗ █████╗ ╚███╔╝ ██████╔╝ ██║ ...
null
146,291
import os import sys def _get_project_meta() -> str: import tomlkit # noqa: WPS433 with open('../pyproject.toml') as pyproject: file_contents = pyproject.read() return tomlkit.parse(file_contents)['tool']['poetry']
null
146,292
def _convert(container, *, deps, backend: str): from returns.interfaces.specific import future, reader if isinstance(container, future.AwaitableFutureN): import anyio return _convert( anyio.run(container.awaitable, backend=backend), # type: ignore deps=deps, ...
Custom ``assert`` function to compare two any containers. The important note here is that this ``assert`` should probably used in tests. Not real application code. It will call all ``Reader`` based containers and ``await`` all ``Future`` based ones. It also works recursively. For example, ``ReaderFutureResult`` will be...
146,293
import types from contextlib import contextmanager from inspect import FrameInfo, stack from typing import ( Callable, ContextManager, Iterator, List, Optional, TypeVar, Union, overload, ) from returns.result import Failure The provided code snippet includes necessary dependencies for i...
Context Manager to active traces collect to the Failures.
146,294
import types from contextlib import contextmanager from inspect import FrameInfo, stack from typing import ( Callable, ContextManager, Iterator, List, Optional, TypeVar, Union, overload, ) from returns.result import Failure _FunctionType = TypeVar('_FunctionType', bound=Callable) The pr...
Decorator to active traces collect to the Failures.
146,295
import types from contextlib import contextmanager from inspect import FrameInfo, stack from typing import ( Callable, ContextManager, Iterator, List, Optional, TypeVar, Union, overload, ) from returns.result import Failure _FunctionType = TypeVar('_FunctionType', bound=Callable) def _ge...
Context Manager/Decorator to active traces collect to the Failures. .. code:: python >>> from inspect import FrameInfo >>> from returns.io import IOResult >>> from returns.result import Result >>> from returns.primitives.tracing import collect_traces >>> with collect_traces(): ... traced_failure = Result.from_failure('...
146,296
from abc import ABCMeta from typing import Any, TypeVar, Union from typing_extensions import TypedDict from returns.interfaces.equable import Equable from returns.primitives.hkt import Kind1 from returns.primitives.types import Immutable _EqualType = TypeVar('_EqualType', bound=Equable) Kind1 = KindN[_InstanceType, _T...
Function to compare similar containers. Compares both their types and their inner values.
146,297
from typing import ( Awaitable, Callable, Generator, NewType, TypeVar, Union, cast, final, ) _FunctionCoroType = TypeVar('_FunctionCoroType', bound=Callable[..., Awaitable]) class ReAwaitable(object): """ Allows to write coroutines that can be awaited multiple times. It works...
Allows to decorate coroutine functions to be awaitable multiple times. .. code:: python >>> import anyio >>> from returns.primitives.reawaitable import reawaitable >>> @reawaitable ... async def return_int() -> int: ... return 1 >>> async def main(): ... instance = return_int() ... return await instance + await instanc...
146,298
from types import MappingProxyType from typing import Final, List, Optional, overload from mypy.checkmember import analyze_member_access from mypy.nodes import ARG_NAMED, ARG_OPT from mypy.types import CallableType, FunctionLike from mypy.types import Type as MypyType from typing_extensions import Literal from returns....
Case when errors are reported and we cannot get ``None``.
146,299
from types import MappingProxyType from typing import Final, List, Optional, overload from mypy.checkmember import analyze_member_access from mypy.nodes import ARG_NAMED, ARG_OPT from mypy.types import CallableType, FunctionLike from mypy.types import Type as MypyType from typing_extensions import Literal from returns....
Errors are not reported, we can get ``None`` when errors happen.
146,300
from types import MappingProxyType from typing import Final, List, Optional, overload from mypy.checkmember import analyze_member_access from mypy.nodes import ARG_NAMED, ARG_OPT from mypy.types import CallableType, FunctionLike from mypy.types import Type as MypyType from typing_extensions import Literal from returns....
Analyzes function call based on passed arguments. Internally uses ``check_call`` from ``mypy``. It does a lot of magic. We also allow to return ``None`` instead of showing errors. This might be helpful for cases when we run intermediate analysis.
146,301
from types import MappingProxyType from typing import Final, List, Optional, overload from mypy.checkmember import analyze_member_access from mypy.nodes import ARG_NAMED, ARG_OPT from mypy.types import CallableType, FunctionLike from mypy.types import Type as MypyType from typing_extensions import Literal from returns....
Transforms many other types to something close to callable type. There's why we need it: - We can use this on real functions - We can use this on ``@overload`` functions - We can use this on instances with ``__call__`` - We can use this on ``Type`` types It can probably work with other types as well. This function allo...
146,302
from typing import ClassVar, Dict, FrozenSet, List, final from mypy.nodes import ARG_OPT, ARG_POS, ARG_STAR, ARG_STAR2, ArgKind from mypy.typeops import get_type_vars from mypy.types import AnyType, CallableType, FunctionLike, Overloaded from mypy.types import Type as MypyType from mypy.types import TypeOfAny, TypeVarT...
Returns a ``CallableType`` or ``Overloaded`` based on case functions.
146,303
from functools import wraps from typing import Callable, TypeVar from mypy.types import AnyType, TypeOfAny _CallableType = TypeVar('_CallableType', bound=Callable) The provided code snippet includes necessary dependencies for implementing the `asserts_fallback_to_any` function. Write a Python function `def asserts_fal...
Falls back to ``Any`` when some ``assert ...`` fails in our plugin code. We often use ``assert isinstance(variable, Instance)`` as a way to ensure correctness in this plugin. But, we need a generic way to handle all possible exceptions in a single manner: just return ``Any`` and hope that someday someone reports it.
146,304
from enum import Enum, unique from typing import Optional, Sequence, Tuple from mypy.checkmember import analyze_member_access from mypy.plugin import ( AttributeContext, FunctionContext, MethodContext, MethodSigContext, ) from mypy.typeops import bind_self from mypy.types import AnyType, CallableType, F...
Ensures that attribute access to ``KindN`` is correct. In other words: .. code:: python from typing import TypeVar from returns.primitives.hkt import KindN from returns.interfaces.mappable import MappableN _MappableType = TypeVar('_MappableType', bound=MappableN) kind: KindN[_MappableType, int, int, int] reveal_type(ki...
146,305
from enum import Enum, unique from typing import Optional, Sequence, Tuple from mypy.checkmember import analyze_member_access from mypy.plugin import ( AttributeContext, FunctionContext, MethodContext, MethodSigContext, ) from mypy.typeops import bind_self from mypy.types import AnyType, CallableType, F...
Infers real type behind ``Kind`` form. Basically, it turns ``Kind[IO, int]`` into ``IO[int]``. The only limitation is that it works with only ``Instance`` type in the first type argument position. So, ``dekind(KindN[T, int])`` will fail.
146,306
from enum import Enum, unique from typing import Optional, Sequence, Tuple from mypy.checkmember import analyze_member_access from mypy.plugin import ( AttributeContext, FunctionContext, MethodContext, MethodSigContext, ) from mypy.typeops import bind_self from mypy.types import AnyType, CallableType, F...
Returns the internal function wrapped as ``Kinded[def]``. Works for ``Kinded`` class when ``__call__`` magic method is used. See :class:`returns.primitives.hkt.Kinded` for more information.
146,307
from enum import Enum, unique from typing import Optional, Sequence, Tuple from mypy.checkmember import analyze_member_access from mypy.plugin import ( AttributeContext, FunctionContext, MethodContext, MethodSigContext, ) from mypy.typeops import bind_self from mypy.types import AnyType, CallableType, F...
Reveals the correct return type of ``Kinded.__call__`` method. Turns ``-> KindN[I, t1, t2, t3]`` into ``-> I[t1, t2, t3]``. Also strips unused type arguments for ``KindN``, so: - ``KindN[IO, int, <nothing>, <nothing>]`` will be ``IO[int]`` - ``KindN[Result, int, str, <nothing>]`` will be ``Result[int, str]`` It also pr...
146,308
from enum import Enum, unique from typing import Optional, Sequence, Tuple from mypy.checkmember import analyze_member_access from mypy.plugin import ( AttributeContext, FunctionContext, MethodContext, MethodSigContext, ) from mypy.typeops import bind_self from mypy.types import AnyType, CallableType, F...
Used to analyze ``@kinded`` method calls. We do this due to ``__get__`` descriptor magic.
146,309
from typing import Callable, List, Tuple from mypy.nodes import ARG_POS from mypy.plugin import FunctionContext, MethodContext, MethodSigContext from mypy.types import AnyType, CallableType, FunctionLike, Instance from mypy.types import Type as MypyType from mypy.types import TypeOfAny, UnionType, get_proper_type from ...
This hook helps when we create the pipeline from sequence of funcs.
146,310
from typing import Callable, List, Tuple from mypy.nodes import ARG_POS from mypy.plugin import FunctionContext, MethodContext, MethodSigContext from mypy.types import AnyType, CallableType, FunctionLike, Instance from mypy.types import Type as MypyType from mypy.types import TypeOfAny, UnionType, get_proper_type from ...
This hook helps when we finally call the created pipeline.
146,311
from typing import Callable, List, Tuple from mypy.nodes import ARG_POS from mypy.plugin import FunctionContext, MethodContext, MethodSigContext from mypy.types import AnyType, CallableType, FunctionLike, Instance from mypy.types import Type as MypyType from mypy.types import TypeOfAny, UnionType, get_proper_type from ...
Helps to fix generics in method signature.
146,312
from itertools import groupby, product from operator import itemgetter from typing import Iterator, List, Optional, Tuple, cast, final from mypy.nodes import ARG_STAR, ARG_STAR2 from mypy.plugin import FunctionContext from mypy.types import AnyType, CallableType, FunctionLike, Overloaded from mypy.types import Type as ...
Returns proper type for curried functions.
146,313
from typing import Final, Iterator, List, Optional, Tuple, final from mypy.nodes import ARG_STAR, ARG_STAR2 from mypy.plugin import FunctionContext from mypy.types import CallableType, FunctionLike, Instance, Overloaded from mypy.types import Type as MypyType from mypy.types import TypeType from returns.contrib.mypy._s...
This hook is used to make typed curring a thing in `returns` project. This plugin is a temporary solution to the problem. It should be later replaced with the official way of doing things. One day functions will have better API and we plan to submit this plugin into ``mypy`` core plugins, so it would not be required. I...
146,314
from mypy.plugin import FunctionContext from mypy.types import Type as MypyType from returns.contrib.mypy._typeops.inference import PipelineInference class PipelineInference(object): """ Very helpful tool to work with functions like ``flow`` and ``pipe``. It iterates all over the given list of pipeline st...
Helps to analyze ``flow`` function calls. By default, ``mypy`` cannot infer and check this function call: .. code:: python >>> from returns.pipeline import flow >>> assert flow( ... 1, ... lambda x: x + 1, ... lambda y: y / 2, ... ) == 1.0 But, this plugin can! It knows all the types for all ``lambda`` functions in the...
146,315
from typing import Final, Optional, Tuple from mypy.maptype import map_instance_to_supertype from mypy.nodes import Expression, GeneratorExpr, TypeInfo from mypy.plugin import MethodContext from mypy.subtypes import is_subtype from mypy.typeops import make_simplified_union from mypy.types import AnyType, CallableType, ...
Used to handle validation and error types in :ref:`do-notation`. What it does? 1. For all types we ensure that only a single container type is used in a single do-notation. We don't allow mixing them. 2. For types with error types (like ``Result``), it inferes what possible errors types can we have. The result is a ``U...
146,316
from typing import Callable, ClassVar, Mapping, Optional, Type, final from mypy.nodes import SymbolTableNode from mypy.plugin import ( AttributeContext, FunctionContext, MethodContext, MethodSigContext, Plugin, ) from mypy.types import CallableType from mypy.types import Type as MypyType from return...
Plugin's public API and entrypoint.
146,317
import inspect from contextlib import contextmanager from typing import ( Any, Callable, Dict, Iterator, NamedTuple, Optional, Type, TypeVar, final, ) import pytest from hypothesis import given from hypothesis import settings as hypothesis_settings from hypothesis import strategies a...
Function to check all defined mathematical laws in a specified container. Should be used like so: .. code:: python from returns.contrib.hypothesis.laws import check_all_laws from returns.io import IO check_all_laws(IO) You can also pass different ``hypothesis`` settings inside: .. code:: python check_all_laws(IO, {'max...
146,318
from functools import partial as _partial from functools import wraps from inspect import BoundArguments, Signature from typing import Any, Callable, Tuple, TypeVar, Union _ReturnType = TypeVar('_ReturnType') The provided code snippet includes necessary dependencies for implementing the `partial` function. Write a Pyt...
Typed partial application. It is just a ``functools.partial`` wrapper with better typing support. We use a custom ``mypy`` plugin to make sure types are correct. Otherwise, it is currently impossible to properly type this function. .. code:: python >>> from returns.curry import partial >>> def sum_two_numbers(first: in...
146,319
from functools import partial as _partial from functools import wraps from inspect import BoundArguments, Signature from typing import Any, Callable, Tuple, TypeVar, Union _ReturnType = TypeVar('_ReturnType') def _eager_curry( function: Callable[..., _ReturnType], argspec, args: tuple, kwargs: dict, ) -...
Typed currying decorator. Currying is a conception from functional languages that does partial applying. That means that if we pass one argument in a function that gets 2 or more arguments, we'll get a new function that remembers all previously passed arguments. Then we can pass remaining arguments, and the function wi...
146,320
from abc import ABCMeta from functools import wraps from inspect import FrameInfo from typing import ( TYPE_CHECKING, Any, Callable, Generator, Iterator, List, NoReturn, Optional, Tuple, Type, TypeVar, Union, final, overload, ) from typing_extensions import ParamS...
Decorator to convert exception-throwing for any kind of Exception.
146,321
from abc import ABCMeta from functools import wraps from inspect import FrameInfo from typing import ( TYPE_CHECKING, Any, Callable, Generator, Iterator, List, NoReturn, Optional, Tuple, Type, TypeVar, Union, final, overload, ) from typing_extensions import ParamS...
Decorator to convert exception-throwing just for a set of Exceptions.
146,322
from abc import ABCMeta from functools import wraps from inspect import FrameInfo from typing import ( TYPE_CHECKING, Any, Callable, Generator, Iterator, List, NoReturn, Optional, Tuple, Type, TypeVar, Union, final, overload, ) from typing_extensions import ParamS...
Decorator to convert exception-throwing function to ``Result`` container. Should be used with care, since it only catches ``Exception`` subclasses. It does not catch ``BaseException`` subclasses. If you need to mark ``async`` function as ``safe``, use :func:`returns.future.future_safe` instead. This decorator only work...
146,323
from abc import ABCMeta from functools import wraps from inspect import FrameInfo from typing import ( TYPE_CHECKING, Any, Callable, Generator, Iterator, List, NoReturn, Optional, Tuple, Type, TypeVar, Union, final, overload, ) from typing_extensions import ParamS...
Decorator to convert exception-throwing function to ``Result`` container. It's very similar with :func:`returns.result.safe`, the difference is when an exception is raised it won't wrap that given exception into a Failure, it'll wrap the argument that lead to the exception. .. code:: python >>> import json >>> from typ...
146,324
from typing import TypeVar from returns.functions import identity from returns.interfaces.bindable import BindableN from returns.maybe import Maybe, Nothing, Some from returns.pipeline import is_successful from returns.primitives.hkt import KindN, kinded from returns.result import Failure, Result, Success _FirstType = ...
Joins two nested containers together. Please, note that it will not join two ``Failure`` for ``Result`` case or two ``Nothing`` for ``Maybe`` case (or basically any two error types) together. .. code:: python >>> from returns.converters import flatten >>> from returns.io import IO >>> from returns.result import Failure...
146,325
from typing import TypeVar from returns.functions import identity from returns.interfaces.bindable import BindableN from returns.maybe import Maybe, Nothing, Some from returns.pipeline import is_successful from returns.primitives.hkt import KindN, kinded from returns.result import Failure, Result, Success _FirstType = ...
Converts ``Result`` container to ``Maybe`` container. .. code:: python >>> from returns.maybe import Some, Nothing >>> from returns.result import Failure, Success >>> assert result_to_maybe(Success(1)) == Some(1) >>> assert result_to_maybe(Success(None)) == Some(None) >>> assert result_to_maybe(Failure(1)) == Nothing >...
146,326
from typing import TypeVar from returns.functions import identity from returns.interfaces.bindable import BindableN from returns.maybe import Maybe, Nothing, Some from returns.pipeline import is_successful from returns.primitives.hkt import KindN, kinded from returns.result import Failure, Result, Success _FirstType = ...
Converts ``Maybe`` container to ``Result`` container. .. code:: python >>> from returns.maybe import Some, Nothing >>> from returns.result import Failure, Success >>> assert maybe_to_result(Some(1)) == Success(1) >>> assert maybe_to_result(Some(None)) == Success(None) >>> assert maybe_to_result(Nothing) == Failure(None...
146,327
from abc import abstractmethod from typing import Callable, Iterable, Tuple, TypeVar, final from returns.interfaces.applicative import ApplicativeN from returns.interfaces.failable import FailableN from returns.primitives.hkt import KindN, kinded _FirstType = TypeVar('_FirstType') The provided code snippet includes ne...
Concats a given item to an existing sequence. We use explicit curring with ``lambda`` function because, ``@curry`` decorator is way slower. And we don't need its features here. But, your functions can use ``@curry`` if you need it.
146,328
from abc import abstractmethod from typing import Callable, Iterable, Tuple, TypeVar, final from returns.interfaces.applicative import ApplicativeN from returns.interfaces.failable import FailableN from returns.primitives.hkt import KindN, kinded _FirstType = TypeVar('_FirstType') _SecondType = TypeVar('_SecondType') _...
Concats two ``FailableN`` using a curried-like function and a fallback. We need both ``.apply`` and ``.lash`` methods here.
146,329
from functools import wraps from typing import Any, Callable, NoReturn, TypeVar from typing_extensions import ParamSpec _FirstType = TypeVar('_FirstType') _SecondType = TypeVar('_SecondType') _ThirdType = TypeVar('_ThirdType') The provided code snippet includes necessary dependencies for implementing the `compose` fun...
Allows function composition. Works as: ``second . first`` or ``first() |> second()``. You can read it as "second after first". .. code:: python >>> assert compose(float, int)('123.5') == 123 We can only compose functions with one argument and one return. Type checked.
146,330
from functools import wraps from typing import Any, Callable, NoReturn, TypeVar from typing_extensions import ParamSpec _FirstType = TypeVar('_FirstType') The provided code snippet includes necessary dependencies for implementing the `tap` function. Write a Python function `def tap( function: Callable[[_FirstType]...
Allows to apply some function and return an argument, instead of a result. Is useful for composing functions with side-effects like ``print()``, ``logger.log()``, etc. .. code:: python >>> assert tap(print)(1) == 1 1 >>> assert tap(lambda _: 1)(2) == 2 See also: - https://github.com/dry-python/returns/issues/145
146,331
from functools import wraps from typing import Any, Callable, NoReturn, TypeVar from typing_extensions import ParamSpec _FirstType = TypeVar('_FirstType') The provided code snippet includes necessary dependencies for implementing the `untap` function. Write a Python function `def untap( function: Callable[[_FirstT...
Allows to apply some function and always return ``None`` as a result. Is useful for composing functions that do some side effects and return some nosense. Is the kind of a reverse of the ``tap`` function. .. code:: python >>> def strange_log(arg: int) -> int: ... print(arg) ... return arg >>> assert untap(strange_log)(...
146,332
from functools import wraps from typing import Any, Callable, NoReturn, TypeVar from typing_extensions import ParamSpec The provided code snippet includes necessary dependencies for implementing the `raise_exception` function. Write a Python function `def raise_exception(exception: Exception) -> NoReturn` to solve the...
Helper function to raise exceptions as a function. It might be required as a compatibility tool for existing APIs. That's how it can be used: .. code:: pycon >>> from returns.result import Failure, Result >>> # Some operation result: >>> user: Result[int, ValueError] = Failure(ValueError('boom')) >>> # Here we unwrap i...
146,333
from functools import wraps from typing import Any, Callable, NoReturn, TypeVar from typing_extensions import ParamSpec _FuncParams = ParamSpec('_FuncParams') The provided code snippet includes necessary dependencies for implementing the `not_` function. Write a Python function `def not_(function: Callable[_FuncParams...
Denies the function returns. .. code:: python >>> from returns.result import Result, Success, Failure >>> def is_successful(result_container: Result[float, int]) -> bool: ... return isinstance(result_container, Success) >>> assert not_(is_successful)(Success(1.0)) is False >>> assert not_(is_successful)(Failure(1)) is ...
146,334
from typing import Callable, TypeVar from returns.interfaces.specific.ioresult import IOResultLikeN from returns.primitives.hkt import Kinded, KindN, kinded from returns.result import Result _FirstType = TypeVar('_FirstType') _SecondType = TypeVar('_SecondType') _ThirdType = TypeVar('_ThirdType') _UpdatedType = TypeVar...
Allows to run managed computation. Managed computations consist of three steps: 1. ``acquire`` when we get some initial resource to work with 2. ``use`` when the main logic is done 3. ``release`` when we release acquired resource Let's look at the example: 1. We need to acquire an opened file to read it later 2. We nee...
146,335
from returns._internal.pipeline.flow import flow def flow( instance: _InstanceType, *functions: _PipelineStepType, ) -> _ReturnType: # type: ignore[type-var] """ Allows to compose a value and up to multiple functions that use this value. All starts with the value itself. Each next function us...
Allows to compose a value and up to 7 functions that use this value. We use a custom ``mypy`` plugin to make sure types are correct. Otherwise, it is currently impossible to properly type this function. Each next function uses the previous result as an input parameter. Here's how it should be used: .. code:: python >>>...
146,337
from typing import TYPE_CHECKING, Awaitable, Callable, TypeVar from returns.primitives.hkt import Kind3, dekind from returns.result import Result, Success _ValueType = TypeVar('_ValueType', covariant=True) _NewValueType = TypeVar('_NewValueType') _ErrorType = TypeVar('_ErrorType', covariant=True) _EnvType = TypeVar('_E...
Async binds a coroutine with container over a value.
146,338
from typing import TYPE_CHECKING, Awaitable, Callable, TypeVar from returns.primitives.hkt import Kind3, dekind from returns.result import Result, Success _ValueType = TypeVar('_ValueType', covariant=True) _NewValueType = TypeVar('_NewValueType') _ErrorType = TypeVar('_ErrorType', covariant=True) _EnvType = TypeVar('_E...
Async composes ``Result`` based function.
146,339
from typing import TYPE_CHECKING, Awaitable, Callable, TypeVar from returns.io import IO from returns.primitives.hkt import Kind1, dekind _ValueType = TypeVar('_ValueType', covariant=True) _NewValueType = TypeVar('_NewValueType') The provided code snippet includes necessary dependencies for implementing the `async_map...
Async maps a function over a value.
146,340
from typing import TYPE_CHECKING, Awaitable, Callable, TypeVar from returns.io import IO from returns.primitives.hkt import Kind1, dekind _ValueType = TypeVar('_ValueType', covariant=True) _NewValueType = TypeVar('_NewValueType') The provided code snippet includes necessary dependencies for implementing the `async_app...
Async applies a container with function over a value.
146,341
from typing import TYPE_CHECKING, Awaitable, Callable, TypeVar from returns.io import IO from returns.primitives.hkt import Kind1, dekind _ValueType = TypeVar('_ValueType', covariant=True) _NewValueType = TypeVar('_NewValueType') Kind1 = KindN[_InstanceType, _TypeArgType1, Any, Any] def dekind( kind: Kin...
Async binds a container over a value.
146,342
from typing import TYPE_CHECKING, Awaitable, Callable, TypeVar from returns.io import IO from returns.primitives.hkt import Kind1, dekind _ValueType = TypeVar('_ValueType', covariant=True) _NewValueType = TypeVar('_NewValueType') The provided code snippet includes necessary dependencies for implementing the `async_bin...
Async binds a coroutine over a value.
146,343
from typing import TYPE_CHECKING, Awaitable, Callable, TypeVar from returns.io import IO from returns.primitives.hkt import Kind1, dekind _ValueType = TypeVar('_ValueType', covariant=True) _NewValueType = TypeVar('_NewValueType') Kind1 = KindN[_InstanceType, _TypeArgType1, Any, Any] def dekind( kind: Kin...
Async binds a coroutine with container over a value.
146,344
from typing import TYPE_CHECKING, Awaitable, Callable, TypeVar from returns.io import IO from returns.primitives.hkt import Kind1, dekind _ValueType = TypeVar('_ValueType', covariant=True) _NewValueType = TypeVar('_NewValueType') class IO( # type: ignore[type-var] BaseContainer, SupportsKind1['IO', _ValueType...
Async binds a container over a value.
146,345
from typing import TYPE_CHECKING, Any, Awaitable, Callable, TypeVar from returns.io import IO, IOResult from returns.primitives.hkt import Kind2, dekind from returns.result import Failure, Result, Success _ValueType = TypeVar('_ValueType', covariant=True) _ErrorType = TypeVar('_ErrorType', covariant=True) class Result...
Swaps value and error types in ``Result``.
146,346
from typing import TYPE_CHECKING, Any, Awaitable, Callable, TypeVar from returns.io import IO, IOResult from returns.primitives.hkt import Kind2, dekind from returns.result import Failure, Result, Success _ValueType = TypeVar('_ValueType', covariant=True) _NewValueType = TypeVar('_NewValueType') _ErrorType = TypeVar('_...
Async maps a function over a value.
146,347
from typing import TYPE_CHECKING, Any, Awaitable, Callable, TypeVar from returns.io import IO, IOResult from returns.primitives.hkt import Kind2, dekind from returns.result import Failure, Result, Success _ValueType = TypeVar('_ValueType', covariant=True) _NewValueType = TypeVar('_NewValueType') _ErrorType = TypeVar('_...
Async maps a function over a value.
146,348
from typing import TYPE_CHECKING, Any, Awaitable, Callable, TypeVar from returns.io import IO, IOResult from returns.primitives.hkt import Kind2, dekind from returns.result import Failure, Result, Success _ValueType = TypeVar('_ValueType', covariant=True) _NewValueType = TypeVar('_NewValueType') _ErrorType = TypeVar('_...
Async binds a container over a value.
146,349
from typing import TYPE_CHECKING, Any, Awaitable, Callable, TypeVar from returns.io import IO, IOResult from returns.primitives.hkt import Kind2, dekind from returns.result import Failure, Result, Success _ValueType = TypeVar('_ValueType', covariant=True) _NewValueType = TypeVar('_NewValueType') _ErrorType = TypeVar('_...
Async binds a coroutine over a value.
146,350
from typing import TYPE_CHECKING, Any, Awaitable, Callable, TypeVar from returns.io import IO, IOResult from returns.primitives.hkt import Kind2, dekind from returns.result import Failure, Result, Success _ValueType = TypeVar('_ValueType', covariant=True) _NewValueType = TypeVar('_NewValueType') _ErrorType = TypeVar('_...
Async binds a coroutine with container over a value.
146,351
from typing import TYPE_CHECKING, Any, Awaitable, Callable, TypeVar from returns.io import IO, IOResult from returns.primitives.hkt import Kind2, dekind from returns.result import Failure, Result, Success _ValueType = TypeVar('_ValueType', covariant=True) _NewValueType = TypeVar('_NewValueType') _ErrorType = TypeVar('_...
Async binds a container returning ``Result`` over a value.
146,352
from typing import TYPE_CHECKING, Any, Awaitable, Callable, TypeVar from returns.io import IO, IOResult from returns.primitives.hkt import Kind2, dekind from returns.result import Failure, Result, Success _ValueType = TypeVar('_ValueType', covariant=True) _NewValueType = TypeVar('_NewValueType') _ErrorType = TypeVar('_...
Async binds a container returning ``IOResult`` over a value.
146,353
from typing import TYPE_CHECKING, Any, Awaitable, Callable, TypeVar from returns.io import IO, IOResult from returns.primitives.hkt import Kind2, dekind from returns.result import Failure, Result, Success _ValueType = TypeVar('_ValueType', covariant=True) _NewValueType = TypeVar('_NewValueType') _ErrorType = TypeVar('_...
Async binds a container returning ``IO`` over a value.
146,354
from typing import TYPE_CHECKING, Any, Awaitable, Callable, TypeVar from returns.io import IO, IOResult from returns.primitives.hkt import Kind2, dekind from returns.result import Failure, Result, Success _ValueType = TypeVar('_ValueType', covariant=True) _NewValueType = TypeVar('_NewValueType') _ErrorType = TypeVar('_...
Async binds a container returning ``IO`` over a value.
146,355
from typing import TYPE_CHECKING, Any, Awaitable, Callable, TypeVar from returns.io import IO, IOResult from returns.primitives.hkt import Kind2, dekind from returns.result import Failure, Result, Success _ValueType = TypeVar('_ValueType', covariant=True) _NewValueType = TypeVar('_NewValueType') _ErrorType = TypeVar('_...
Async binds a container returning ``IO`` over a value.
146,356
from typing import TYPE_CHECKING, Any, Awaitable, Callable, TypeVar from returns.io import IO, IOResult from returns.primitives.hkt import Kind2, dekind from returns.result import Failure, Result, Success _ValueType = TypeVar('_ValueType', covariant=True) _ErrorType = TypeVar('_ErrorType', covariant=True) _NewErrorType...
Async alts a function over a value.
146,357
from typing import TYPE_CHECKING, Any, Awaitable, Callable, TypeVar from returns.io import IO, IOResult from returns.primitives.hkt import Kind2, dekind from returns.result import Failure, Result, Success _ValueType = TypeVar('_ValueType', covariant=True) _ErrorType = TypeVar('_ErrorType', covariant=True) _NewErrorType...
Async lashes a function returning a container over a value.
146,358
from typing import TYPE_CHECKING, Any, Awaitable, Callable, TypeVar from returns.io import IO, IOResult from returns.primitives.hkt import Kind2, dekind from returns.result import Failure, Result, Success _NewErrorType = TypeVar('_NewErrorType') class Result( # type: ignore[type-var] BaseContainer, SupportsKi...
Async failure unit factory.
146,359
from typing import TYPE_CHECKING, Any, Awaitable, Callable, TypeVar from returns.io import IO, IOResult from returns.primitives.hkt import Kind2, dekind from returns.result import Failure, Result, Success _ValueType = TypeVar('_ValueType', covariant=True) _NewValueType = TypeVar('_NewValueType') _ErrorType = TypeVar('_...
Async composes ``Result`` based function.
146,360
from typing import TypeVar, Union from returns.interfaces.unwrappable import Unwrappable from returns.pipeline import is_successful _FirstType = TypeVar('_FirstType') _SecondType = TypeVar('_SecondType') class Unwrappable(Generic[_FirstType, _SecondType]): """ Represents containers that can unwrap and return i...
Unwraps either successful or failed value. .. code:: python >>> from returns.io import IO, IOSuccess, IOFailure >>> from returns.methods import unwrap_or_failure >>> assert unwrap_or_failure(IOSuccess(1)) == IO(1) >>> assert unwrap_or_failure(IOFailure('a')) == IO('a')
146,361
from functools import wraps from typing import Callable, Generic, TypeVar, Union, final from typing_extensions import ParamSpec _ReturnType = TypeVar('_ReturnType') _FuncParams = ParamSpec('_FuncParams') class Trampoline(Generic[_ReturnType]): """ Represents a wrapped function call. Primitive to convert rec...
Convert functions using recursion to regular functions. Trampolines allow to unwrap recursion into a regular ``while`` loop, which does not raise any ``RecursionError`` ever. Since python does not have TCO (tail call optimization), we have to provide this helper. This is done by wrapping real function calls into :class...
146,362
from typing import Callable, TypeVar from returns.interfaces.mappable import MappableN from returns.primitives.hkt import Kinded, KindN, kinded _FirstType = TypeVar('_FirstType') _SecondType = TypeVar('_SecondType') _ThirdType = TypeVar('_ThirdType') _UpdatedType = TypeVar('_UpdatedType') _MappableKind = TypeVar('_Mapp...
Lifts function to be wrapped in a container for better composition. In other words, it modifies the function's signature from: ``a -> b`` to: ``Container[a] -> Container[b]`` This is how it should be used: .. code:: python >>> from returns.io import IO >>> from returns.pointfree import map_ >>> def example(argument: in...
146,363
from typing import TYPE_CHECKING, Callable, TypeVar from returns.interfaces.specific.reader_future_result import ( ReaderFutureResultLikeN, ) from returns.primitives.hkt import Kinded, KindN, kinded _FirstType = TypeVar('_FirstType') _SecondType = TypeVar('_SecondType') _ThirdType = TypeVar('_ThirdType') _UpdatedTy...
Lifts function from ``RequiresContextFutureResult`` for better composition. In other words, it modifies the function's signature from: ``a -> RequiresContextFutureResult[env, b, c]`` to: ``Container[env, a, c]`` -> ``Container[env, b, c]`` .. code:: python >>> import anyio >>> from returns.context import ReaderFutureRe...
146,364
from typing import Callable, TypeVar from returns.interfaces.altable import AltableN from returns.primitives.hkt import Kinded, KindN, kinded _FirstType = TypeVar('_FirstType') _SecondType = TypeVar('_SecondType') _ThirdType = TypeVar('_ThirdType') _UpdatedType = TypeVar('_UpdatedType') _AltableKind = TypeVar('_Altable...
Lifts function to be wrapped in a container for better composition. In other words, it modifies the function's signature from: ``a -> b`` to: ``Container[a] -> Container[b]`` This is how it should be used: .. code:: python >>> from returns.io import IOFailure, IOSuccess >>> from returns.pointfree import alt >>> def exa...
146,365
from __future__ import annotations from typing import TYPE_CHECKING, Callable, TypeVar from returns.interfaces.specific.reader import ReaderLike2, ReaderLike3 from returns.primitives.hkt import Kind2, Kind3, Kinded, kinded _FirstType = TypeVar('_FirstType') _SecondType = TypeVar('_SecondType') _UpdatedType = TypeVar('_...
Composes successful container with a function that returns a container. In other words, it modifies the function's signature from: ``a -> RequresContext[b, c]`` to: ``Container[a, c] -> Container[b, c]`` .. code:: python >>> from returns.pointfree import bind_context2 >>> from returns.context import Reader >>> def exam...
146,366
from __future__ import annotations from typing import TYPE_CHECKING, Callable, TypeVar from returns.interfaces.specific.reader import ReaderLike2, ReaderLike3 from returns.primitives.hkt import Kind2, Kind3, Kinded, kinded _FirstType = TypeVar('_FirstType') _SecondType = TypeVar('_SecondType') _ThirdType = TypeVar('_Th...
Composes successful container with a function that returns a container. In other words, it modifies the function's signature from: ``a -> RequresContext[b, c]`` to: ``Container[a, c] -> Container[b, c]`` .. code:: python >>> from returns.context import RequiresContext, RequiresContextResult >>> from returns.result impo...
146,367
from __future__ import annotations from typing import TYPE_CHECKING, Callable, TypeVar from returns.interfaces.specific.ioresult import IOResultLikeN from returns.primitives.hkt import Kinded, KindN, kinded _FirstType = TypeVar('_FirstType') _SecondType = TypeVar('_SecondType') _ThirdType = TypeVar('_ThirdType') _Updat...
Composes successful container with a function that returns a container. In other words, it modifies the function's signature from: ``a -> IOResult[b, c]`` to: ``Container[a, c] -> Container[b, c]`` .. code:: python >>> from returns.io import IOResult, IOSuccess >>> from returns.context import RequiresContextIOResult >>...
146,368
from typing import Awaitable, Callable, TypeVar from returns.interfaces.specific.future import FutureLikeN from returns.primitives.hkt import Kinded, KindN, kinded _FirstType = TypeVar('_FirstType') _SecondType = TypeVar('_SecondType') _ThirdType = TypeVar('_ThirdType') _UpdatedType = TypeVar('_UpdatedType') _FutureKin...
Compose a container and ``async`` function returning a container. In other words, it modifies the function's signature from: ``a -> Awaitable[Container[b]]`` to: ``Container[a] -> Container[b]`` This is how it should be used: .. code:: python >>> import anyio >>> from returns.future import Future >>> from returns.io im...
146,369
from __future__ import annotations from typing import TYPE_CHECKING, Callable, TypeVar from returns.interfaces.specific.reader_result import ReaderResultLikeN from returns.primitives.hkt import Kinded, KindN, kinded _FirstType = TypeVar('_FirstType') _SecondType = TypeVar('_SecondType') _ThirdType = TypeVar('_ThirdType...
Composes successful container with a function that returns a container. In other words, it modifies the function's signature from: ``a -> ReaderResult[b, c, e]`` to: ``Container[a, c, e] -> Container[b, c, e]`` .. code:: python >>> from returns.pointfree import bind_context_result >>> from returns.context import Reader...
146,370
from typing import Awaitable, Callable, TypeVar from returns.future import Future from returns.interfaces.specific.future import FutureLikeN from returns.primitives.hkt import Kinded, KindN, kinded _FirstType = TypeVar('_FirstType') _SecondType = TypeVar('_SecondType') _ThirdType = TypeVar('_ThirdType') _UpdatedType = ...
Compose a container and async function returning ``Future``. In other words, it modifies the function signature from: ``a -> Awaitable[Future[b]]`` to: ``Container[a] -> Container[b]`` This is how it should be used: .. code:: python >>> import anyio >>> from returns.pointfree import bind_async_future >>> from returns.f...
146,371
from typing import Awaitable, Callable, TypeVar from returns.future import FutureResult from returns.interfaces.specific.future_result import FutureResultLikeN from returns.primitives.hkt import Kinded, KindN, kinded _FirstType = TypeVar('_FirstType') _SecondType = TypeVar('_SecondType') _ThirdType = TypeVar('_ThirdTyp...
Compose a container and async function returning ``FutureResult``. In other words, it modifies the function signature from: ``a -> Awaitable[FutureResult[b, c]]`` to: ``Container[a, c] -> Container[b, c]`` This is how it should be used: .. code:: python >>> import anyio >>> from returns.pointfree import bind_async_futu...
146,372
from typing import Callable, Optional, Type, TypeVar, Union, overload from returns.context import NoDeps from returns.interfaces.failable import DiverseFailableN, SingleFailableN from returns.methods.cond import internal_cond from returns.primitives.hkt import Kinded, KindN _ValueType = TypeVar('_ValueType') _ErrorType...
Reduce the boilerplate when choosing paths with ``SingleFailableN``.
146,373
from typing import Callable, Optional, Type, TypeVar, Union, overload from returns.context import NoDeps from returns.interfaces.failable import DiverseFailableN, SingleFailableN from returns.methods.cond import internal_cond from returns.primitives.hkt import Kinded, KindN _ValueType = TypeVar('_ValueType') _ErrorType...
Reduce the boilerplate when choosing paths with ``DiverseFailableN``.
146,374
from typing import Callable, Optional, Type, TypeVar, Union, overload from returns.context import NoDeps from returns.interfaces.failable import DiverseFailableN, SingleFailableN from returns.methods.cond import internal_cond from returns.primitives.hkt import Kinded, KindN _ValueType = TypeVar('_ValueType') _ErrorType...
Reduce the boilerplate when choosing paths. Works with ``SingleFailableN`` (e.g. ``Maybe``) and ``DiverseFailableN`` (e.g. ``Result``). Example using ``cond`` with the ``Result`` container: .. code:: python >>> from returns.pointfree import cond >>> from returns.result import Failure, Result, Success >>> assert cond(Re...
146,375
from typing import Awaitable, Callable, TypeVar from returns.interfaces.specific.future import FutureLikeN from returns.primitives.hkt import Kinded, KindN, kinded _FirstType = TypeVar('_FirstType') _SecondType = TypeVar('_SecondType') _ThirdType = TypeVar('_ThirdType') _UpdatedType = TypeVar('_UpdatedType') _FutureKin...
Composes a container a regular ``async`` function. This function should return plain, non-container value. In other words, it modifies the function's signature from: ``a -> Awaitable[b]`` to: ``Container[a] -> Container[b]`` This is how it should be used: .. code:: python >>> import anyio >>> from returns.future import...
146,376
from typing import Callable, TypeVar, Union from returns.interfaces.failable import DiverseFailableN from returns.primitives.hkt import Kinded, KindN, kinded _FirstType = TypeVar('_FirstType') _NewFirstType = TypeVar('_NewFirstType') _SecondType = TypeVar('_SecondType') _NewSecondType = TypeVar('_NewSecondType') _Third...
Composes successful container with a function that returns a container. Similar to :func:`~returns.pointfree.bind` but has different type. It returns ``Result[ValueType, Union[OldErrorType, NewErrorType]]`` instead of ``Result[ValueType, OldErrorType]``. So, it can be more useful in some situations. Probably with speci...
146,377
from typing import Callable, TypeVar from returns.interfaces.specific.ioresult import IOResultLikeN from returns.primitives.hkt import Kind3, Kinded, kinded from returns.result import Result _FirstType = TypeVar('_FirstType') _NewFirstType = TypeVar('_NewFirstType') _SecondType = TypeVar('_SecondType') _ThirdType = Typ...
Composes inner ``Result`` with ``IOResultLike`` returning function. Can be useful when you need an access to both states of the result. .. code:: python >>> from returns.io import IOResult, IOSuccess, IOFailure >>> from returns.pointfree import compose_result >>> from returns.result import Result >>> def modify_string(...
146,378
from typing import Callable, TypeVar from returns.interfaces.lashable import LashableN from returns.primitives.hkt import Kinded, KindN, kinded _FirstType = TypeVar('_FirstType') _SecondType = TypeVar('_SecondType') _ThirdType = TypeVar('_ThirdType') _UpdatedType = TypeVar('_UpdatedType') _LashableKind = TypeVar('_Lash...
Turns function's input parameter from a regular value to a container. In other words, it modifies the function signature from: ``a -> Container[b]`` to: ``Container[a] -> Container[b]`` Similar to :func:`returns.pointfree.bind`, but works for failed containers. This is how it should be used: .. code:: python >>> from r...
146,379
from typing import TYPE_CHECKING, Awaitable, Callable, TypeVar from returns.interfaces.specific.reader_future_result import ( ReaderFutureResultLikeN, ) from returns.primitives.hkt import Kinded, KindN, kinded _FirstType = TypeVar('_FirstType') _SecondType = TypeVar('_SecondType') _ThirdType = TypeVar('_ThirdType')...
Lifts function from ``RequiresContextFutureResult`` for better composition. In other words, it modifies the function's signature from: ``async a -> RequiresContextFutureResult[env, b, c]`` to: ``Container[env, a, c]`` -> ``Container[env, b, c]`` .. code:: python >>> import anyio >>> from returns.context import ReaderFu...
146,380
from typing import Callable, TypeVar from returns.interfaces.applicative import ApplicativeN from returns.primitives.hkt import Kinded, KindN, kinded _FirstType = TypeVar('_FirstType') _SecondType = TypeVar('_SecondType') _ThirdType = TypeVar('_ThirdType') _UpdatedType = TypeVar('_UpdatedType') _ApplicativeKind = TypeV...
Turns container containing a function into a callable. In other words, it modifies the function signature from: ``Container[a -> b]`` to: ``Container[a] -> Container[b]`` This is how it should be used: .. code:: python >>> from returns.pointfree import apply >>> from returns.maybe import Some, Nothing >>> def example(a...
146,381
from typing import Callable, TypeVar from returns.future import FutureResult from returns.interfaces.specific.future_result import FutureResultLikeN from returns.primitives.hkt import Kinded, KindN, kinded _FirstType = TypeVar('_FirstType') _SecondType = TypeVar('_SecondType') _ThirdType = TypeVar('_ThirdType') _Update...
Compose a container and async function returning ``FutureResult``. In other words, it modifies the function signature from: ``a -> FutureResult[b, c]`` to: ``Container[a, c] -> Container[b, c]`` This is how it should be used: .. code:: python >>> import anyio >>> from returns.pointfree import bind_future_result >>> fro...
146,382
from typing import Callable, TypeVar from returns.future import Future from returns.interfaces.specific.future import FutureLikeN from returns.primitives.hkt import Kinded, KindN, kinded _FirstType = TypeVar('_FirstType') _SecondType = TypeVar('_SecondType') _ThirdType = TypeVar('_ThirdType') _UpdatedType = TypeVar('_U...
Compose a container and sync function returning ``Future``. In other words, it modifies the function signature from: ``a -> Future[b]`` to: ``Container[a] -> Container[b]`` Similar to :func:`returns.pointfree.lash`, but works for successful containers. This is how it should be used: .. code:: python >>> import anyio >>...
146,383
from __future__ import annotations from typing import TYPE_CHECKING, Callable, TypeVar from returns.interfaces.specific.reader_ioresult import ReaderIOResultLikeN from returns.primitives.hkt import Kinded, KindN, kinded _FirstType = TypeVar('_FirstType') _SecondType = TypeVar('_SecondType') _ThirdType = TypeVar('_Third...
Lifts function from ``RequiresContextIOResult`` for better composition. In other words, it modifies the function's signature from: ``a -> RequiresContextIOResult[env, b, c]`` to: ``Container[env, a, c]`` -> ``Container[env, b, c]`` .. code:: python >>> import anyio >>> from returns.context import ( ... RequiresContextF...
146,384
from typing import Callable, TypeVar from returns.interfaces.bimappable import BiMappableN from returns.primitives.hkt import Kinded, KindN, kinded _FirstType = TypeVar('_FirstType') _SecondType = TypeVar('_SecondType') _ThirdType = TypeVar('_ThirdType') _UpdatedType1 = TypeVar('_UpdatedType1') _UpdatedType2 = TypeVar(...
Maps container on both: first and second arguments. Can be used to synchronize state on both success and failure. This is how it should be used: .. code:: python >>> from returns.io import IOSuccess, IOFailure >>> from returns.pointfree import bimap >>> def first(argument: int) -> float: ... return argument / 2 >>> def...
146,385
from typing import Callable, Optional, TypeVar from returns.interfaces.specific.maybe import MaybeLikeN from returns.primitives.hkt import Kinded, KindN, kinded _FirstType = TypeVar('_FirstType') _SecondType = TypeVar('_SecondType') _ThirdType = TypeVar('_ThirdType') _UpdatedType = TypeVar('_UpdatedType') _MaybeLikeKin...
Binds a function returning optional value over a container. In other words, it modifies the function's signature from: ``a -> Optional[b]`` to: ``Container[a] -> Container[b]`` .. code:: python >>> from typing import Optional >>> from returns.pointfree import bind_optional >>> from returns.maybe import Some, Nothing >>...
146,386
from __future__ import annotations from typing import TYPE_CHECKING, Callable, TypeVar from returns.interfaces.specific.result import ResultLikeN from returns.primitives.hkt import Kinded, KindN, kinded _FirstType = TypeVar('_FirstType') _SecondType = TypeVar('_SecondType') _ThirdType = TypeVar('_ThirdType') _UpdatedTy...
Composes successful container with a function that returns a container. In other words, it modifies the function's signature from: ``a -> Result[b, c]`` to: ``Container[a, c] -> Container[b, c]`` .. code:: python >>> from returns.io import IOSuccess >>> from returns.context import RequiresContextResult >>> from returns...
146,387
from __future__ import annotations from typing import TYPE_CHECKING, Callable, TypeVar from returns.interfaces.specific.io import IOLikeN from returns.primitives.hkt import Kinded, KindN, kinded _FirstType = TypeVar('_FirstType', contravariant=True) _SecondType = TypeVar('_SecondType') _ThirdType = TypeVar('_ThirdType'...
Composes successful container with a function that returns a container. In other words, it modifies the function's signature from: ``a -> IO[b]`` to: ``Container[a, c] -> Container[b, c]`` .. code:: python >>> from returns.io import IOSuccess, IOFailure >>> from returns.io import IO >>> from returns.pointfree import bi...