NamedKeyDict¶
- class lsst.daf.butler.NamedKeyDict(*args: Any)¶
Bases:
NamedKeyMutableMapping
[K
,V
]Dictionary wrapper for named keys.
Requires keys to have a
.name
attribute, and permits lookups using either key objects or their names.Names can be used in place of keys when updating existing items, but not when adding new items.
It is assumed (but asserted) that all name equality is equivalent to key equality, either because the key objects define equality this way, or because different objects with the same name are never included in the same dictionary.
- Parameters:
- *args
typing.Any
All positional constructor arguments are forwarded directly to
dict
. Keyword arguments are not accepted, because plain strings are not valid keys forNamedKeyDict
.
- *args
- Raises:
- AttributeError
Raised when an attempt is made to add an object with no
.name
attribute to the dictionary.- AssertionError
Raised when multiple keys have the same name.
Attributes Summary
Return set of names associated with the keys, in the same order.
Methods Summary
byName
()Return a
dict
with names as keys and theself
values.copy
()Return a new
NamedKeyDict
with the same elements.freeze
()Disable all mutators.
items
()keys
()values
()Attributes Documentation
Methods Documentation
- copy() NamedKeyDict[K, V] ¶
Return a new
NamedKeyDict
with the same elements.
- freeze() NamedKeyMapping[K, V] ¶
Disable all mutators.
Effectively transforms
self
into an immutable mapping.- Returns:
- self
NamedKeyMapping
While
self
is modified in-place, it is also returned with a type annotation that reflects its new, frozen state; assigning it to a new variable (and considering any previous references invalidated) should allow for more accurate static type checking.
- self
- items() a set-like object providing a view on D's items ¶
- keys() a set-like object providing a view on D's keys ¶
- values() an object providing a view on D's values ¶