Skip to content

ObjectNode

Base classes

Name Children Inherits
NodeBase
promptantic.form.nodes
Common to all nodes.

⋔ Inheritance diagram

graph TD
  3079200183["nodes.ObjectNode"]
  1324256109["nodes.NodeBase"]
  2751680898["builtins.object"]
  1324256109 --> 3079200183
  2751680898 --> 1324256109

🛈 DocStrings

Bases: NodeBase

Named fields, plus optionally free keys (additionalProperties with a schema).

Source code in src/promptantic/form/nodes.py
@dataclass(frozen=True, eq=False)
class ObjectNode(NodeBase):
    """Named fields, plus optionally free keys (``additionalProperties`` with a schema)."""

    kind: Literal["object"] = "object"
    build_properties: Callable[[], tuple[Property, ...]] | None = field(default=None, repr=False)
    build_additional: Callable[[], FormNode] | None = field(default=None, repr=False)
    """Schema of keys beyond the named ones; ``None``: no extra keys can be entered."""
    min_properties: int | None = None
    max_properties: int | None = None

    @cached_property
    def properties(self) -> tuple[Property, ...]:
        return () if self.build_properties is None else self.build_properties()

    @cached_property
    def additional(self) -> FormNode | None:
        """Node for the values of free keys, or ``None`` when there are none."""
        return None if self.build_additional is None else self.build_additional()

    @property
    def is_map(self) -> bool:
        """Only free keys (e.g. ``dict[str, int]``): a key/value editor."""
        return not self.properties and self.build_additional is not None

additional cached property

additional: FormNode | None

Node for the values of free keys, or None when there are none.

build_additional class-attribute instance-attribute

build_additional: Callable[[], FormNode] | None = field(default=None, repr=False)

Schema of keys beyond the named ones; None: no extra keys can be entered.

is_map property

is_map: bool

Only free keys (e.g. dict[str, int]): a key/value editor.

:fa-brands-github: Show source on GitHub