Skip to main content

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

Project description

🎭 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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

masks_fp-1.0.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

masks_fp-1.0.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file masks_fp-1.0.0.tar.gz.

File metadata

  • Download URL: masks_fp-1.0.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.2 Linux/5.15.167.4-microsoft-standard-WSL2

File hashes

Hashes for masks_fp-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2267d745ac90bacaabd221854e009a95c943c2035f90a58718b6c29103ccd14f
MD5 19d70027cc6cd942b32118f80b20ed5e
BLAKE2b-256 1cdc31dea36f82a3360d75b429b2e94f13e01acdf2a0a3c085b998c2125b8dd4

See more details on using hashes here.

File details

Details for the file masks_fp-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: masks_fp-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.2 Linux/5.15.167.4-microsoft-standard-WSL2

File hashes

Hashes for masks_fp-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7285e4d7339816cb8930841cf3115fc986854feba8affaedf0337645fc079977
MD5 5ad78db29158aba43f1504e59453a699
BLAKE2b-256 22968c2189e15477fcc9fa28dfa12ed209987ead737d5ac1dcf5b383c3274e96

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page