nustack

refs.shape

ShapeRef hierarchy: structured container Ref with named-slot navigation.

Module nu.domains.shape.refs.shape.

ShapeRef hierarchy: structured container Ref with named-slot navigation.

ShapeRef = shape.MappingForm + StructuredRef MutableShapeRef = shape.MutableMappingForm + ShapeRef ReactiveShapeRef = shape.ReactiveMappingForm + MutableShapeRef

A Shape is structurally a mapping (dict[str, object]). Using the shape-domain MappingForm (which already weaves generic MappingForm + shape CollectionForm) gives all 3 tiers the full mapping surface (keys/values/items/extract/getitem, len, contains) PLUS shape ops (exists/missing/set/erase), without a separate ItemForm in the MRO.

Slot navigation is available two ways:

  • Attribute: ref.field via __getattr__ (MRO fallback)
  • Bracket: ref["field"] via __getitem__ override

Both produce a correctly-typed child Ref from the slot definition.

Form composition provides: base: exists(), missing(), extract(), keys(), values(), items(), len(), contains(), [key], .attr mutable: + store(v), erase(), set(k,v), delete(k), update(), ... reactive: + on_change() (generic), on_child_change(), on_children_change(), on_descendants_change() (shape-domain)

  • MutableShapeRef / ReactiveShapeRef are included.
  • ReactiveShapeRef composes with shape.ReactiveMappingForm (shape IS a mapping).
  • wrap* abstract methods from MappingForm raise NotImplementedError on the blueprint. Substrate subclasses fill them in (consistent with MappingRef etc.).
NameSortCallMeaning
MutableShapeRefrefMutableShapeRef(address, shape_type, parent_ref=None, owner_shape=None)Mutable structured container Ref.
ReactiveShapeRefrefReactiveShapeRef(address, shape_type, parent_ref=None, owner_shape=None)Reactive structured container Ref.
ShapeRefrefShapeRef(address, shape_type, parent_ref=None, owner_shape=None)Structured container Ref; slot navigation via attribute or bracket access.

MutableShapeRef

Mutable structured container Ref.

MutableShapeRef(address, shape_type, parent_ref=None, owner_shape=None)

Path nu.domains.shape.MutableShapeRef. Kind Ref, sort ref, cardinality scalar.

Adds: store(v), erase(), set(k,v), delete(k), update(), ... (from shape MutableMappingForm) on top of ShapeRef.

Inherited methods

From nu.forms.collections.abc.mapping.MutableMappingForm:

CallBuildsMeaning
.set_item(key, value)AnySet the value at key, inserting the key if it's missing: mapping[key] = value.
.del_item(key)AnyDelete the entry at key: del mapping[key].
.update(other)AnyWrite other's entries into self, in place: mapping.update(other).
.pop(key, default=None)ValueResultTRemove key and yield its value, or default if key is missing.
.popitem()ValueResultTRemove and yield an arbitrary (key, value) pair: mapping.popitem().
.setdefault(key, default=None)ValueResultTValue at key, inserting default there first if key is missing.
.merge_update(other)CollectionResultTMerge other into self in place, and yield self: mapping |= other.
.clear()AnyRemove all entries: mapping.clear().

From nu.domains.shape.refs.shape.ShapeRef:

CallBuildsMeaning
a[key]StructuredRefNavigate into shape slots via bracket access; mirror of getattr.

From nu.forms.collections.abc.mapping.MappingForm:

CallBuildsMeaning
.keys()CollectionResultTAll keys of the mapping: mapping.keys().
.values()CollectionResultTAll values of the mapping: mapping.values().
.items()CollectionResultTAll (key, value) pairs of the mapping: mapping.items().
.get_item(key, default=None)ValueResultTValue at key, falling back to default: mapping.get_item(key, default).
.copy()CollectionResultTShallow copy of self: mapping.copy().
.reversed_keys()CollectionResultTKeys in reverse insertion order: reversed(mapping).
.reversed_values()CollectionResultTValues in reverse insertion order: reversed(mapping.values()).
.reversed_items()CollectionResultT(key, value) pairs in reverse insertion order: reversed(mapping.items()).
.merge(other)CollectionResultTSelf and other merged into a new mapping: mapping | other.

From nu.forms.collections.abc.collection.CollectionForm:

CallBuildsMeaning
.extract()objectMaterialise the full subtree rooted at self.

From nu.forms.collections.abc.sized.SizedForm:

CallBuildsMeaning
.len()IntLength of self.

From nu.forms.collections.abc.iterable.IterableForm:

CallBuildsMeaning
iter(a)Iterator[ElementT]Open self into a lazy iterator stream (Python's iter).

From nu.forms.collections.abc.container.ContainerForm:

CallBuildsMeaning
.contains(item)BoolWhether item is a member of self.

From nu.domains.shape.forms.collection.MutableCollectionForm:

CallBuildsMeaning
.set(value)SetCmdBuild a SetCmd.
.erase()EraseBuild an Erase.
.init(value)IfDoSet value iff the collection is currently missing.

From nu.domains.shape.forms.collection.CollectionForm:

CallBuildsMeaning
.exists()ExistsBuild an Exists query.
.missing()MissingBuild a Missing query.

From nu.lang.forms.Form:

CallBuildsMeaning
.is_empty()BoolTrue if this Form yields the EMPTY sentinel.
.is_invalid()BoolTrue if this Form yields the INVALID sentinel.
.is_sentinel()BoolTrue if this Form yields either sentinel (EMPTY or INVALID).
.not_empty()BoolTrue if this Form does not yield EMPTY.
.not_invalid()BoolTrue if this Form does not yield INVALID.

Undocumented: example.

ReactiveShapeRef

Reactive structured container Ref.

ReactiveShapeRef(address, shape_type, parent_ref=None, owner_shape=None)

Path nu.domains.shape.ReactiveShapeRef. Kind Ref, sort ref, cardinality scalar.

Adds: on_change() (generic), on_child_change(), on_children_change(), on_descendants_change() (shape-domain, from shape.ReactiveMappingForm) on top of MutableShapeRef.

shape.ReactiveMappingForm is used because a Shape IS a mapping; this provides the full reactive surface (generic on_change + shape tree-aware).

Inherited methods

From nu.forms.collections.abc.mapping.ReactiveMappingForm:

CallBuildsMeaning
.on_change()objectSubscribe to any change on this mapping slot.

From nu.forms.collections.abc.mapping.MutableMappingForm:

CallBuildsMeaning
.set_item(key, value)AnySet the value at key, inserting the key if it's missing: mapping[key] = value.
.del_item(key)AnyDelete the entry at key: del mapping[key].
.update(other)AnyWrite other's entries into self, in place: mapping.update(other).
.pop(key, default=None)ValueResultTRemove key and yield its value, or default if key is missing.
.popitem()ValueResultTRemove and yield an arbitrary (key, value) pair: mapping.popitem().
.setdefault(key, default=None)ValueResultTValue at key, inserting default there first if key is missing.
.merge_update(other)CollectionResultTMerge other into self in place, and yield self: mapping |= other.
.clear()AnyRemove all entries: mapping.clear().

From nu.domains.shape.refs.shape.ShapeRef:

CallBuildsMeaning
a[key]StructuredRefNavigate into shape slots via bracket access; mirror of getattr.

From nu.forms.collections.abc.mapping.MappingForm:

CallBuildsMeaning
.keys()CollectionResultTAll keys of the mapping: mapping.keys().
.values()CollectionResultTAll values of the mapping: mapping.values().
.items()CollectionResultTAll (key, value) pairs of the mapping: mapping.items().
.get_item(key, default=None)ValueResultTValue at key, falling back to default: mapping.get_item(key, default).
.copy()CollectionResultTShallow copy of self: mapping.copy().
.reversed_keys()CollectionResultTKeys in reverse insertion order: reversed(mapping).
.reversed_values()CollectionResultTValues in reverse insertion order: reversed(mapping.values()).
.reversed_items()CollectionResultT(key, value) pairs in reverse insertion order: reversed(mapping.items()).
.merge(other)CollectionResultTSelf and other merged into a new mapping: mapping | other.

From nu.forms.collections.abc.collection.CollectionForm:

CallBuildsMeaning
.extract()objectMaterialise the full subtree rooted at self.

From nu.forms.collections.abc.sized.SizedForm:

CallBuildsMeaning
.len()IntLength of self.

From nu.forms.collections.abc.iterable.IterableForm:

CallBuildsMeaning
iter(a)Iterator[ElementT]Open self into a lazy iterator stream (Python's iter).

From nu.forms.collections.abc.container.ContainerForm:

CallBuildsMeaning
.contains(item)BoolWhether item is a member of self.

From nu.domains.shape.forms.collection.ReactiveCollectionForm:

CallBuildsMeaning
.on_child_change(address)OnChildChangeObserve changes at a specific child address.
.on_children_change()OnChildrenChangeObserve changes across all direct children.
.on_descendants_change()OnDescendantsChangeObserve changes across descendants matching pattern.

From nu.domains.shape.forms.collection.MutableCollectionForm:

CallBuildsMeaning
.set(value)SetCmdBuild a SetCmd.
.erase()EraseBuild an Erase.
.init(value)IfDoSet value iff the collection is currently missing.

From nu.domains.shape.forms.collection.CollectionForm:

CallBuildsMeaning
.exists()ExistsBuild an Exists query.
.missing()MissingBuild a Missing query.

From nu.lang.forms.Form:

CallBuildsMeaning
.is_empty()BoolTrue if this Form yields the EMPTY sentinel.
.is_invalid()BoolTrue if this Form yields the INVALID sentinel.
.is_sentinel()BoolTrue if this Form yields either sentinel (EMPTY or INVALID).
.not_empty()BoolTrue if this Form does not yield EMPTY.
.not_invalid()BoolTrue if this Form does not yield INVALID.

Undocumented: example.

ShapeRef

Structured container Ref; slot navigation via attribute or bracket access.

ShapeRef(address, shape_type, parent_ref=None, owner_shape=None)

Path nu.domains.shape.ShapeRef. Kind Ref, sort ref, cardinality scalar.

API: full MappingForm surface: exists(), missing(), extract(), keys(), values(), items(), len(), contains(), [key], .attr from shape MappingForm. _wrap_* methods raise NotImplementedError on the blueprint; substrate subclasses override them.

Methods

a[key]

Navigate into shape slots via bracket access; mirror of getattr.

Builds StructuredRef.

Arguments

NameTypeDefaultMeaning
keyobject

Undocumented: example.

Inherited methods

From nu.forms.collections.abc.mapping.MappingForm:

CallBuildsMeaning
.keys()CollectionResultTAll keys of the mapping: mapping.keys().
.values()CollectionResultTAll values of the mapping: mapping.values().
.items()CollectionResultTAll (key, value) pairs of the mapping: mapping.items().
.get_item(key, default=None)ValueResultTValue at key, falling back to default: mapping.get_item(key, default).
.copy()CollectionResultTShallow copy of self: mapping.copy().
.reversed_keys()CollectionResultTKeys in reverse insertion order: reversed(mapping).
.reversed_values()CollectionResultTValues in reverse insertion order: reversed(mapping.values()).
.reversed_items()CollectionResultT(key, value) pairs in reverse insertion order: reversed(mapping.items()).
.merge(other)CollectionResultTSelf and other merged into a new mapping: mapping | other.

From nu.forms.collections.abc.collection.CollectionForm:

CallBuildsMeaning
.extract()objectMaterialise the full subtree rooted at self.

From nu.forms.collections.abc.sized.SizedForm:

CallBuildsMeaning
.len()IntLength of self.

From nu.forms.collections.abc.iterable.IterableForm:

CallBuildsMeaning
iter(a)Iterator[ElementT]Open self into a lazy iterator stream (Python's iter).

From nu.forms.collections.abc.container.ContainerForm:

CallBuildsMeaning
.contains(item)BoolWhether item is a member of self.

From nu.domains.shape.forms.collection.CollectionForm:

CallBuildsMeaning
.exists()ExistsBuild an Exists query.
.missing()MissingBuild a Missing query.

From nu.lang.forms.Form:

CallBuildsMeaning
.is_empty()BoolTrue if this Form yields the EMPTY sentinel.
.is_invalid()BoolTrue if this Form yields the INVALID sentinel.
.is_sentinel()BoolTrue if this Form yields either sentinel (EMPTY or INVALID).
.not_empty()BoolTrue if this Form does not yield EMPTY.
.not_invalid()BoolTrue if this Form does not yield INVALID.

Undocumented: example.

On this page