Skip to content

Support for terms with Literal types #511

@kiranandcode

Description

@kiranandcode

While implementing part of pact I ran into a situation where it would be helpful to be able to construct terms of type Literal[...] fixed set of values.

from effectful.ops.syntax import defop, NotHandled

@defop
def Price() -> Literal[5,10,20,50,80,120,150,200]:
    raise NotHandled

Price()

Currently this fails with an error about __mro__:

  File "/Users/kirancodes/Documents/code/effectful/effectful/ops/syntax.py", line 515, in apply_cast
    return __dispatch(dispatch_type)(dispatch_type, op, *args, **kwargs)
           ~~~~~~~~~~^^^^^^^^^^^^^^^
...
  File "/Users/kirancodes/.local/share/uv/python/cpython-3.13.9-macos-aarch64-none/lib/python3.13/functools.py", line 765, in _compose_mro
    bases = set(cls.__mro__)
                ^^^^^^^^^^^
AttributeError: __mro__. Did you mean: '__or__'?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions