A template literal parser; parts are its parts, as given.
Attributes#
| Attribute | Type | Description |
|---|---|---|
parts | tuple[Codec[Any, Any, RD_co, RE_co] | LiteralPart, ...] |
Functions#
__init__#
__init__(ast, parts) -> None| Parameter | Type | Description |
|---|---|---|
ast | AST | |
parts | tuple[Codec[Any, Any, RD_co, RE_co] | LiteralPart, ...] |
pipe#
pipe[B](f) -> Bf(self). One function per call, as Effect.pipe.
| Parameter | Type | Description |
|---|---|---|
f | Callable[[Self], B] |
Returns B
def pipe[B](self, f: Callable[[Self], B], /) -> B:
"""``f(self)``. One function per call, as ``Effect.pipe``."""
return f(self)annotate#
annotate(**annotations) -> SelfThis schema with annotations merged over its own: identifier
names it in messages (Expected <identifier>), message
replaces its message, title / description / ... document it.
On a schema with checks they annotate the last check.
| Parameter | Type | Description |
|---|---|---|
annotations | object = {} |
Returns Self
def annotate(self, /, **annotations: object) -> Self:
"""This schema with annotations merged over its own: ``identifier``
names it in messages (``Expected <identifier>``), ``message``
replaces its message, ``title`` / ``description`` / ... document it.
On a schema with checks they annotate the last check."""
return replace(self, ast=annotate(self.ast, annotations))annotate_encoded#
annotate_encoded(**annotations) -> SelfThis schema with annotations on its encoded side (Effect's
annotateEncoded); a schema without a transformation is its own
encoded side.
| Parameter | Type | Description |
|---|---|---|
annotations | object = {} |
Returns Self
def annotate_encoded(self, /, **annotations: object) -> Self:
"""This schema with annotations on its encoded side (Effect's
``annotateEncoded``); a schema without a transformation is its own
encoded side."""
return replace(self, ast=annotate(self.ast.flip(), annotations).flip())override_to_equivalence#
override_to_equivalence[A, E, RD, RE](f) -> Bottom[A, E, RD, RE]This schema compared by f() in S.to_equivalence (Effect's
overrideToEquivalence).
| Parameter | Type | Description |
|---|---|---|
f | Callable[[], Callable[[A, A], bool]] |
Returns Bottom[A, E, RD, RE]
def override_to_equivalence[A, E, RD, RE](
self: Bottom[A, E, RD, RE], f: Callable[[], Callable[[A, A], bool]], /
) -> Bottom[A, E, RD, RE]:
"""This schema compared by ``f()`` in ``S.to_equivalence`` (Effect's
``overrideToEquivalence``)."""
def derive(_: tuple[object, ...]) -> Callable[[A, A], bool]:
return f()
return self.annotate(to_equivalence=derive)override_to_formatter#
override_to_formatter[A, E, RD, RE](f) -> Bottom[A, E, RD, RE]This schema written by f() in S.to_formatter (Effect's
overrideToFormatter).
| Parameter | Type | Description |
|---|---|---|
f | Callable[[], Callable[[A], str]] |
Returns Bottom[A, E, RD, RE]
def override_to_formatter[A, E, RD, RE](
self: Bottom[A, E, RD, RE], f: Callable[[], Callable[[A], str]], /
) -> Bottom[A, E, RD, RE]:
"""This schema written by ``f()`` in ``S.to_formatter`` (Effect's
``overrideToFormatter``)."""
def derive(_: tuple[object, ...]) -> Callable[[A], str]:
return f()
return self.annotate(to_formatter=derive)annotate_key#
annotate_key(**annotations) -> SelfThis schema with annotations for the struct key holding it
(Effect's annotateKey): message_missing_key replaces
"Missing key".
| Parameter | Type | Description |
|---|---|---|
annotations | object = {} |
Returns Self
def annotate_key(self, /, **annotations: object) -> Self:
"""This schema with annotations for the struct key holding it
(Effect's ``annotateKey``): ``message_missing_key`` replaces
``"Missing key"``."""
key_annotations = {**(self.ast.key_annotations or {}), **annotations}
return replace(self, ast=replace_context(self.ast, key_annotations=key_annotations))check#
check(first, *rest) -> SelfThis schema with checks run, in order, on each value it accepts
(S.is_min_length(3), S.make_filter(...), ...).
| Parameter | Type | Description |
|---|---|---|
first | Check[T_co] | |
rest | Check[T_co] = () |
Returns Self
def check(self, first: Check[T_co], /, *rest: Check[T_co]) -> Self:
"""This schema with checks run, in order, on each value it accepts
(``S.is_min_length(3)``, ``S.make_filter(...)``, ...)."""
return replace(self, ast=append_checks(self.ast, (first, *rest)))make#
make[A](input, **options) -> Ainput checked against the decoded side, its missing keys and
elements filled by their constructor defaults
(with_constructor_default); raises SchemaError.
| Parameter | Type | Description |
|---|---|---|
input | A | |
options | Unpack[ParseOptions] = {} |
Returns A
def make[A](
self: Bottom[A, object, object, object], input: A, /, **options: Unpack[ParseOptions]
) -> A:
"""``input`` checked against the decoded side, its missing keys and
elements filled by their constructor defaults
(``with_constructor_default``); raises ``SchemaError``."""
match run_now(Maker(self.ast.to_type()).parse(input, options, True)):
case Success(value):
return cast("A", value)
case failure:
raise_schema_failure(failure.cause.map(SchemaError), CONSTRUCTOR)make_option#
make_option[A](input, **options) -> Option[A]Some(value), or None when input is invalid.
| Parameter | Type | Description |
|---|---|---|
input | A | |
options | Unpack[ParseOptions] = {} |
Returns Option[A]
def make_option[A](
self: Bottom[A, object, object, object], input: A, /, **options: Unpack[ParseOptions]
) -> Option[A]:
"""``Some(value)``, or ``None`` when ``input`` is invalid."""
match run_now(Maker(self.ast.to_type()).parse(input, options, True)):
case Success(value):
return Some(cast("A", value))
case failure:
schema_error_of(failure.cause.map(SchemaError), OPTION)
return Nonemake_effect#
make_effect[A](input, **options) -> Effect[A, Issue]make as an effect failing with the bare Issue, as Effect's
makeEffect (so an enclosing schema can add its path).
| Parameter | Type | Description |
|---|---|---|
input | A | |
options | Unpack[ParseOptions] = {} |
Returns Effect[A, Issue]
def make_effect[A](
self: Bottom[A, object, object, object], input: A, /, **options: Unpack[ParseOptions]
) -> Effect[A, Issue]:
"""``make`` as an effect failing with the bare ``Issue``, as Effect's
``makeEffect`` (so an enclosing schema can add its path)."""
parsed = Maker(self.ast.to_type()).parse(input, options, False)
return cast("Effect[A, Issue]", to_effect(parsed))