GitHub

API reference for Enum.

The members of enum, encoded as their values (Effect's Enum, whose values are the members). Decoding takes a value (or a member) and gives the member; encoding gives the member's value. Values must be strings or finite numbers.

side says what the node does: "decode" (value to member), "encode" (member to value), "type" (members) or "encoded" (values). Checks apply to members.

Attributes

AttributeTypeDescription
enumtype[enum.Enum]
sideEnumSide = 'decode'
tag= 'Enum'
memberstuple[enum.Enum, ...]
parse= parse_by_interpreting

Functions

__init__

__init__(enum, side='decode', *, annotations=None, checks=None, key_annotations=None, encoding=None, encoding_checks=None, optional_key=False, constructor_default=None) -> None
ParameterTypeDescription
enumtype[enum.Enum]
sideEnumSide = 'decode'
annotationsAnnotations | None = None
checksChecks | None = None
key_annotationsAnnotations | None = None
encodingEncoding | None = None
encoding_checksChecks | None = None
optional_keybool = False
constructor_defaultEffect[object, Issue] | None = None

get_expected

get_expected() -> str

Returns str

def get_expected(self) -> str:
    if self.side in ("type", "encode"):
        return self.enum.__name__
    return " | ".join(format_literal(m.value) for m in self.enum)

interpret

interpret(input, options) -> ParseResult
ParameterTypeDescription
inputobject
optionsParseOptions

Returns ParseResult

def interpret(self, input: object, options: ParseOptions) -> ParseResult:
    if self.encoding is not None:
        return AST.interpret(self, input, options)
    return self.parse_local(input, options)

parse_local

parse_local(input, options) -> ParseResult
ParameterTypeDescription
inputobject
optionsParseOptions

Returns ParseResult

def parse_local(self, input: object, options: ParseOptions) -> ParseResult:
    if self.side != "encode":
        return AST.parse_local(self, input, options)
    # Checks describe members: run them on the member, then encode it.
    return map_value(
        replace(self, side="type").parse_local(input, options),
        lambda member: cast("enum.Enum", member).value,
    )

is_opaque

is_opaque() -> bool

Returns bool

def is_opaque(self) -> bool:
    return self.side in ("decode", "encode")

owner

owner() -> AST

The node whose body this one shares (Effect's getContextOwner): a copy with another key context, or a flip's encoded side, which has its own encoding. Its decoded side and its flip are the owner's.

Returns AST

def owner(self) -> AST:
    """The node whose body this one shares (Effect's ``getContextOwner``): a copy with
    another key context, or a flip's encoded side, which has its own encoding. Its decoded
    side and its flip are the owner's."""
    return self.context_owner or self

key_context_owner

key_context_owner() -> AST

The node this one is with only its key context changed, encoding included, else itself: copies that are one schema to derivations and JSON Schema definitions, each in its own key context (Effect's replaceContext test of getContextOwner).

Returns AST

def key_context_owner(self) -> AST:
    """The node this one is with only its key context changed, encoding included, else
    itself: copies that are one schema to derivations and JSON Schema definitions, each
    in its own key context (Effect's ``replaceContext`` test of ``getContextOwner``)."""
    owner = self.owner()
    return owner if owner.encoding is self.encoding else self

resolve

resolve() -> Annotations | None

The annotations that describe the node: its last check's when it has checks, else its own (Effect's resolveAnnotations).

Returns Annotations | None

def resolve(self) -> Annotations | None:
    """The annotations that describe the node: its last check's when it
    has checks, else its own (Effect's ``resolveAnnotations``)."""
    return self.checks[-1].annotations if self.checks else self.annotations

expected

expected() -> str

The text "Expected <...>" messages use: the identifier annotation, else get_expected() (Effect's getExpected).

Returns str

def expected(self) -> str:
    """The text ``"Expected <...>"`` messages use: the ``identifier``
    annotation, else ``get_expected()`` (Effect's ``getExpected``)."""
    identifier = (self.resolve() or {}).get("identifier")
    return identifier if isinstance(identifier, str) else self.get_expected()

flip

flip() -> AST

The node that encodes what this one decodes. A node without an encoding flips its parts; a leaf is its own flip.

Returns AST

def flip(self) -> AST:
    """The node that encodes what this one decodes. A node without an
    encoding flips its parts; a leaf is its own flip."""
    if not self._flip_side:
        encoding = self.encoding
        owner = self.owner()
        if encoding is not None:
            flipped = flip_encoding(self, encoding)
        elif owner is not self:
            # A contextual copy's flip is its owner's, in the copy's
            # context: one schema to derivations.
            flipped_owner = owner.flip()
            flipped = self if flipped_owner is owner else _with_context(flipped_owner, self)
        else:
            flipped = self._flip()
        self._flip_side.append(flipped)
    return self._flip_side[0]

to_type

to_type() -> AST

The node's decoded side: no encoding, its parts' decoded sides. A contextual copy's is its owner's, with the copy's key context.

Returns AST

def to_type(self) -> AST:
    """The node's decoded side: no encoding, its parts' decoded sides. A
    contextual copy's is its owner's, with the copy's key context."""
    owner = self.owner()
    if owner is not self:
        typed = owner.to_type()
        if typed is owner and self.encoding is None:
            return self
        return _with_context(typed, self)
    if not self._type_side:
        base = replace_encoding(self, None)
        typed = base._to_type()
        encoding_checks = typed.encoding_checks
        if encoding_checks is not None:
            # Checks of the encoded side hold for the decoded one when no
            # part transforms; else only those of the shape (a size).
            if _preserves_encoding_checks(base):
                promoted = encoding_checks
            elif typed._keeps_structural_checks():
                promoted = structural_checks(encoding_checks)
            else:
                promoted = None
            typed = copy(
                typed, encoding_checks=None, checks=join_checks(typed.checks, promoted)
            )
        self._type_side.append(typed)
        if typed is not self and not typed._type_side:  # pragma: no mutate, memo only
            typed._type_side.append(typed)
    return self._type_side[0]

children

children() -> Iterable[AST]

The nodes this one parses its parts with (Effect's recur); a Suspend's target is not made for this.

Returns Iterable[AST]

def children(self) -> Iterable[AST]:
    """The nodes this one parses its parts with (Effect's ``recur``); a
    ``Suspend``'s target is not made for this."""
    return ()