nustack
ReferenceNu STDmem

refs.shape

Dict shape reference: structured container backed by nested dict.

Module nustd.mem.refs.shape.

Dict shape reference: structured container backed by nested dict.

Field descent (ShapeRef.field) is the blueprint's __getattr__: it resolves the slot to the field's own mem ref (StrRef, IntRef, ...) with this ref as parent_ref, so navigation rides the substrate automatically.

NameSortCallMeaning
ShapeRefrefShapeRef(address, shape_type, parent_ref=None, owner_shape=None)A nested Shape slot in the dict substrate, stored as an inner dict.

ShapeRef

A nested Shape slot in the dict substrate, stored as an inner dict.

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

Path nustd.mem.ShapeRef. Kind Ref, sort ref, cardinality scalar.

Attribute access descends: ref.field resolves the named slot on the held Shape class and hands back that field's own ref, parented here, so dot chains navigate arbitrarily deep before anything is read. The mapping calls on the ref itself act on the inner dict as a whole.

Notes

  • The inner dict does not have to exist first: writing through a field creates every level on the way down.
  • Nothing enforces the Shape: keys the class never declared can sit in the same dict and are read only through the mapping calls.

Example

class Order(nu.Shape):
    symbol = nustd.mem.StrRef.slot()
class Book(nu.Shape):
    best = nustd.mem.ShapeRef.slot(Order)
data = {}
ctx = nu.Context().bind(dict, data, Book)
_ = nu.run(Book.best.symbol.set("AAPL"), ctx)
data
{'best': {'symbol': 'AAPL'}}

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.

On this page