Attributes#
| Attribute | Type | Description |
|---|---|---|
tag | = 'Boolean' |
Functions#
__init__#
__init__(*, annotations=None, checks=None, key_annotations=None, encoding=None, encoding_checks=None, optional_key=False, constructor_default=None) -> None| Parameter | Type | Description |
|---|---|---|
annotations | Annotations | None = None | |
checks | Checks | None = None | |
key_annotations | Annotations | None = None | |
encoding | Encoding | None = None | |
encoding_checks | Checks | None = None | |
optional_key | bool = False | |
constructor_default | Effect[object, Issue] | None = None |
get_expected#
get_expected() -> strReturns str
def get_expected(self) -> str:
return "boolean"accepts#
accepts(input) -> bool| Parameter | Type | Description |
|---|---|---|
input | object |
Returns bool
def accepts(self, input: object) -> bool:
return isinstance(input, bool)owner#
owner() -> ASTThe 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 selfkey_context_owner#
key_context_owner() -> ASTThe 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 selfresolve#
resolve() -> Annotations | NoneThe 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.annotationsexpected#
expected() -> strThe 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()parse#
parse(input, options) -> ParseResultinput decoded through the node's encoding, then checked
against the node and its checks: an Exit, or an Effect when
a transformation needs one. Once a decoder is installed in the
compiler registry (pyfect.schema.compiler), the node's registry
entry parses it.
| Parameter | Type | Description |
|---|---|---|
input | object | |
options | ParseOptions |
Returns ParseResult
def parse(self, input: object, options: ParseOptions) -> ParseResult:
"""``input`` decoded through the node's encoding, then checked
against the node and its checks: an ``Exit``, or an ``Effect`` when
a transformation needs one. Once a decoder is installed in the
compiler registry (``pyfect.schema.compiler``), the node's registry
entry parses it."""
if _dispatch is not None:
return _dispatch(self, input, options)
encoding = self.encoding
if encoding is not None:
return decode_chain(self, encoding, input, options)
# ``parse_local``, inlined: this is the hot path.
if input is MISSING:
return MISSING_EXIT
result = self._parse(input, options)
if (self.checks is None and self.encoding_checks is None) or options.get("disable_checks"):
return result
if type(result) is Success:
return self._run_checks(input, result.value, options)
return flat_map(result, lambda value: self._run_checks(input, value, options))interpret#
interpret(input, options) -> ParseResultparse without the registry: the interpreter (Effect's
Interpreter.compile). A subclass overriding it sets parse = parse_by_interpreting.
| Parameter | Type | Description |
|---|---|---|
input | object | |
options | ParseOptions |
Returns ParseResult
def interpret(self, input: object, options: ParseOptions) -> ParseResult:
"""``parse`` without the registry: the interpreter (Effect's
``Interpreter.compile``). A subclass overriding it sets ``parse =
parse_by_interpreting``."""
encoding = self.encoding
if encoding is not None:
return decode_chain(self, encoding, input, options)
# ``parse_local``, inlined: this is the hot path.
if input is MISSING:
return MISSING_EXIT
result = self._parse(input, options)
if (self.checks is None and self.encoding_checks is None) or options.get("disable_checks"):
return result
if type(result) is Success:
return self._run_checks(input, result.value, options)
return flat_map(result, lambda value: self._run_checks(input, value, options))parse_local#
parse_local(input, options) -> ParseResultinput checked against the node itself (not its encoding) and
its checks. MISSING stays missing. A subclass overriding it
overrides parse too (parse inlines this).
| Parameter | Type | Description |
|---|---|---|
input | object | |
options | ParseOptions |
Returns ParseResult
def parse_local(self, input: object, options: ParseOptions) -> ParseResult:
"""``input`` checked against the node itself (not its encoding) and
its checks. ``MISSING`` stays missing. A subclass overriding it
overrides ``parse`` too (``parse`` inlines this)."""
if input is MISSING:
return MISSING_EXIT
result = self._parse(input, options)
if (self.checks is None and self.encoding_checks is None) or options.get("disable_checks"):
return result
if type(result) is Success:
return self._run_checks(input, result.value, options)
return flat_map(result, lambda value: self._run_checks(input, value, options))flip#
flip() -> ASTThe 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() -> ASTThe 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 ()is_opaque#
is_opaque() -> boolIts values may have another shape than its input though it has no
encoding: a Suspend (not made to find out), a class's or an enum's
decoding.
Returns bool
def is_opaque(self) -> bool:
"""Its values may have another shape than its input though it has no
encoding: a ``Suspend`` (not made to find out), a class's or an enum's
decoding."""
return False