Catalog PyPI
PACKAGE EXPLORERView in registry

affection

PyPI

Algebraic Effect for modern Python.

Versions collected1
Direct dependencies1From release 0.1.1
Last observed20 Oct, 21:03 UTC

README

Version 0.1.1 documentation

Affection

Algebraic Effect for modern Python.

Tips: I strongly recommend you to read Algebraic Effects for the Rest of Us before you start.

Affection is a small library that implements Algebraic Effect for Python. It leverages asyncio, decorator and with syntax for a smooth experience.

Warning: Please note that until Higher Rank Type Variants are supported in Python, the Effect.handle API will be quite ugly.

Usage

This project is designed to be a single file project.

You can either directly copy it into your project, or add affection from PyPI with your favorite package manager.

from affection import Effect, Handle, effect, perform


class Log(Effect[None]):
    def __init__(self, content: str):
        self.content = content


def get_name(name: str | None = None) -> str:
    perform(Log(f"Getting name with {name}"))
    return perform(effect("ask_name", str)) if name is None else name


def main():
    with Handle() as h:

        @Log.handle(h)
        def _(l: Log):
            print(l.content)

        @effect("ask_name", str).handle(h)
        def _(_) -> str:
            return "Default"

        perform(Log("Test parent log"))

        with Handle() as i_h:
            @Log.handle(h)
            def _(l: Log):
                print("Inner", l.content.lower())
            print(get_name("Ann"))
            print(get_name())

if __name__ == "__main__":
    main()
    """
    Test parent log
    Inner getting name with ann
    Ann
    Inner getting name with none
    Default
    """

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
0.1.118 Jul 20221

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 21:03 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:f87e1e1aee4d694e51e609e2ca4d49ba05410f2c85fbd994fa5707eb5a30a0fa