Field¶
didactic.api.field ¶
field(
*,
default: T,
converter: Callable[[FieldValue], FieldValue]
| None = ...,
alias: str | None = ...,
description: str | None = ...,
examples: tuple[FieldValue, ...] = ...,
deprecated: bool = ...,
nominal: bool = ...,
constraint: Opaque | None = ...,
coercion: Callable[..., FieldValue] | None = ...,
usage_mode: Literal[
"readwrite", "computed", "materialised"
] = ...,
extras: Mapping[str, Opaque] | None = ...,
opaque: bool = ...,
) -> T
field(
*,
default_factory: Callable[[], T],
converter: Callable[[FieldValue], FieldValue]
| None = ...,
alias: str | None = ...,
description: str | None = ...,
examples: tuple[FieldValue, ...] = ...,
deprecated: bool = ...,
nominal: bool = ...,
constraint: Opaque | None = ...,
coercion: Callable[..., FieldValue] | None = ...,
usage_mode: Literal[
"readwrite", "computed", "materialised"
] = ...,
extras: Mapping[str, Opaque] | None = ...,
opaque: bool = ...,
) -> T
field(
*,
converter: Callable[[FieldValue], FieldValue]
| None = ...,
alias: str | None = ...,
description: str | None = ...,
examples: tuple[FieldValue, ...] = ...,
deprecated: bool = ...,
nominal: bool = ...,
constraint: Opaque | None = ...,
coercion: Callable[..., FieldValue] | None = ...,
usage_mode: Literal[
"readwrite", "computed", "materialised"
] = ...,
extras: Mapping[str, Opaque] | None = ...,
opaque: bool = ...,
) -> Any
field(
*,
default: FieldValue | _Missing = MISSING,
default_factory: Callable[[], FieldValue] | None = None,
converter: Callable[[FieldValue], FieldValue]
| None = None,
alias: str | None = None,
description: str | None = None,
examples: tuple[FieldValue, ...] = (),
deprecated: bool = False,
nominal: bool = False,
constraint: Opaque | None = None,
coercion: Callable[..., FieldValue] | None = None,
usage_mode: Literal[
"readwrite", "computed", "materialised"
] = "readwrite",
extras: Mapping[str, Opaque] | None = None,
opaque: bool = False,
) -> Field
Construct a Field descriptor.
| PARAMETER | DESCRIPTION |
|---|---|
default
|
Default value. If both
TYPE:
|
default_factory
|
Zero-argument callable returning a default. Mutually exclusive
with
TYPE:
|
converter
|
PEP 712 converter applied before type validation.
TYPE:
|
alias
|
Serialisation alias. Useful when JSON/TOML payloads use a different name than the Python attribute.
TYPE:
|
description
|
Human-readable field description. Populates Theory metadata.
TYPE:
|
examples
|
Example values for documentation and code generation.
TYPE:
|
deprecated
|
Mark the field as deprecated; warning emitted at construction.
TYPE:
|
nominal
|
If
TYPE:
|
constraint
|
Constraint metadata equivalent to placing it in
TYPE:
|
coercion
|
A coercion lens or callable. Stored on the FieldSpec and available to downstream tooling, but the Model construction path does not yet route values through it.
TYPE:
|
usage_mode
|
Field role:
TYPE:
|
extras
|
Extra metadata for downstream tooling.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Field
|
A field descriptor. With the metaclass's |
See Also
Field : the descriptor class returned by this function. didactic.models._meta : the metaclass that consumes Fields and produces FieldSpec records.
Examples:
didactic.api.Field
dataclass
¶
Field(
default: DefaultOrMissing = MISSING,
default_factory: Callable[[], FieldValue] | None = None,
converter: Callable[[FieldValue], FieldValue]
| None = None,
alias: str | None = None,
description: str | None = None,
examples: tuple[FieldValue, ...] = (),
deprecated: bool = False,
nominal: bool = False,
constraint: Opaque | None = None,
coercion: Callable[..., FieldValue] | None = None,
usage_mode: Literal[
"readwrite", "computed", "materialised"
] = "readwrite",
extras: Mapping[str, Opaque] | None = None,
opaque: bool = False,
)
Field descriptor produced by the field constructor.
Field instances appear as the right-hand side of class-attribute assignments in a Model body::
class User(dx.Model):
id: str
email: str = dx.field(description="primary contact")
The metaclass extracts the configuration and produces a
FieldSpec; Field itself carries no runtime
behaviour beyond holding the configuration values.
| PARAMETER | DESCRIPTION |
|---|---|
default
|
Default value, or
TYPE:
|
default_factory
|
Zero-argument callable returning a default value.
TYPE:
|
converter
|
PEP 712 converter. Runs before type validation and any
TYPE:
|
alias
|
External name for serialisation (input/output rename).
TYPE:
|
description
|
Human-readable description; populates the Theory's field
metadata. Equivalent to
TYPE:
|
examples
|
Example values for documentation and code generation.
TYPE:
|
deprecated
|
If
TYPE:
|
nominal
|
If
TYPE:
|
constraint
|
A constraint object; typically an
TYPE:
|
coercion
|
A coercion lens or callable; stored on the FieldSpec for downstream tooling, not consumed by Model construction yet.
TYPE:
|
usage_mode
|
Field role:
TYPE:
|
extras
|
Extra metadata for downstream tooling.
TYPE:
|
See Also
field : the function that returns Field instances.
FieldSpec : the resolved record produced by the metaclass.
didactic.api.FieldSpec
dataclass
¶
FieldSpec(
name: str,
annotation: TypeForm | TypeVar | ForwardRef,
translation: TypeTranslation,
default: DefaultOrMissing = MISSING,
default_factory: Callable[[], FieldValue] | None = None,
converter: Callable[[FieldValue], FieldValue]
| None = None,
alias: str | None = None,
description: str | None = None,
examples: tuple[FieldValue, ...] = (),
deprecated: bool = False,
nominal: bool = False,
usage_mode: Literal[
"readwrite", "computed", "materialised"
] = "readwrite",
axioms: tuple[str, ...] = (),
extras: Mapping[str, Opaque] = (
lambda: cast("dict[str, Opaque]", {})
)(),
is_opaque: bool = False,
)
Fully resolved field record produced by the metaclass.
A FieldSpec captures everything didactic needs to read or write one
field: the sort name, the encode/decode pair, the default, the
metadata, and any axioms induced by Annotated[...] constraints.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The Python attribute name.
TYPE:
|
annotation
|
The original (resolved) type annotation.
TYPE:
|
translation
|
The result of running
TYPE:
|
default
|
The default value, or
TYPE:
|
default_factory
|
Zero-argument default-producing callable, or
TYPE:
|
converter
|
PEP 712 converter applied before type validation.
TYPE:
|
alias
|
External serialisation name, or
TYPE:
|
description
|
Field description (from
TYPE:
|
examples
|
Example values.
TYPE:
|
deprecated
|
Whether the field is deprecated.
TYPE:
|
nominal
|
Whether the field contributes to vertex identity.
TYPE:
|
usage_mode
|
Field role.
TYPE:
|
axioms
|
Axiom strings induced by
TYPE:
|
extras
|
Unrecognised
TYPE:
|
make_default ¶
Produce a default value, calling the factory if present.
| RETURNS | DESCRIPTION |
|---|---|
FieldValue or _Missing
|
The default. |