File: unsafe.py

package info (click to toggle)
python-returns 0.26.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,652 kB
  • sloc: python: 11,000; makefile: 18
file content (31 lines) | stat: -rw-r--r-- 829 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from typing import TypeVar

from returns.io import IO

_ValueType = TypeVar('_ValueType')


def unsafe_perform_io(wrapped_in_io: IO[_ValueType]) -> _ValueType:
    """
    Compatibility utility and escape mechanism from ``IO`` world.

    Just unwraps the internal value
    from :class:`returns.io.IO` container.
    Should be used with caution!
    Since it might be overused by lazy and ignorant developers.

    It is recommended to have only one place (module / file)
    in your program where you allow unsafe operations.

    We recommend to use ``import-linter`` to enforce this rule.

    .. code:: python

      >>> from returns.io import IO
      >>> assert unsafe_perform_io(IO(1)) == 1

    See also:
        - https://github.com/seddonym/import-linter

    """
    return wrapped_in_io._inner_value  # noqa: SLF001