🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

masks-fp

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

masks-fp

Masks fp is a powerful wrapping tool that preserves meta and anatomical information. 🎭

1.0.0
PyPI
Maintainers
1

🎭 Masks fp

Functional wrapping for Python.

Advanced ⬦ Powerful ⬦ Tooling

GitHub Actions Workflow Status PyPI - Version PyPI - Python Version

Background

Wrapping is a technique targeting function extensibility, taking metadata of one function and merging it with another, including any intended additional functionality, forming a new function.

Usage

Mask fp is a powerful tool made for wrapping functions and is built on top of the functools.wraps function. The masks function allows for quick creation of wrapper function look-alikes by placing the masks decorator over target wrapper functions and calling it along with the desired target wrapped function. Furthermore, the masks function will preserve type hinting, signatures, annotations, and the application of default arg and kwarg values, for an enhanced developer experience and potentially advanced use cases.

Features

  • Automatic application of default arguments during calls, just as it would originally.
  • Fully applied __signature__ and __annotations__ for wrappers; parameters of wrapped and return annotation of wrapper.
  • Type hinting for newly created wrapper functions! ✨

Install

Using pip

pip install masks-fp

Or using Poetry

poetry add masks-fp

Example

from collections.abc import Callable, Iterable

from mask_fp import masks


def decorator(f: Callable[..., Iterable[int]]) -> Callable:
    @masks(f)
    def wrapper(*args, **kwargs) -> dict[str, int | Iterable[int]]:
        """
        From ``wrapper`` ``docstring``. 👋
        """
        print(f"Sum of {f(*args, **kwargs)} is {sum(f(*args, **kwargs))}. 🎓")

        return f(*args, **kwargs)

    return wrapper


@decorator
def wrapped(a: int, /, b: int = 2, *, c: int = 3) -> tuple[int, int, int]:
    """
    From ``wrapped`` ``docstring``. 👋
    """
    return (a, b, c)

Without using default values

>>> print(wrapped(1, 2, c=3))
Sum of (1, 2, 3) is 6. 🎓
(1, 2, 3)

Using default values

>>> print(wrapped(1))
Sum of (1, 2, 3) is 6. 🎓
(1, 2, 3)

Keywords

python

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts