LSST Applications g00274db5b6+edbf708997,g00d0e8bbd7+edbf708997,g199a45376c+5137f08352,g1fd858c14a+1d4b6db739,g262e1987ae+f4d9505c4f,g29ae962dfc+7156fb1a53,g2cef7863aa+73c82f25e4,g35bb328faa+edbf708997,g3e17d7035e+5b3adc59f5,g3fd5ace14f+852fa6fbcb,g47891489e3+6dc8069a4c,g53246c7159+edbf708997,g64539dfbff+9f17e571f4,g67b6fd64d1+6dc8069a4c,g74acd417e5+ae494d68d9,g786e29fd12+af89c03590,g7ae74a0b1c+a25e60b391,g7aefaa3e3d+536efcc10a,g7cc15d900a+d121454f8d,g87389fa792+a4172ec7da,g89139ef638+6dc8069a4c,g8d7436a09f+28c28d8d6d,g8ea07a8fe4+db21c37724,g92c671f44c+9f17e571f4,g98df359435+b2e6376b13,g99af87f6a8+b0f4ad7b8d,gac66b60396+966efe6077,gb88ae4c679+7dec8f19df,gbaa8f7a6c5+38b34f4976,gbf99507273+edbf708997,gc24b5d6ed1+9f17e571f4,gca7fc764a6+6dc8069a4c,gcc769fe2a4+97d0256649,gd7ef33dd92+6dc8069a4c,gdab6d2f7ff+ae494d68d9,gdbb4c4dda9+9f17e571f4,ge410e46f29+6dc8069a4c,geaed405ab2+e194be0d2b,w.2025.47
LSST Data Management Base Package
Loading...
Searching...
No Matches
lsst.pex.config.dictField.Dict Class Reference
Inheritance diagram for lsst.pex.config.dictField.Dict:
lsst.pex.config.configDictField.ConfigDict lsst.pex.config.dictField.DictField lsst.pex.config.configDictField.ConfigDictField

Public Member Functions

 __init__ (self, Config config, DictField field, Mapping[KeyTypeVar, ItemTypeVar] value, *, list[StackFrame]|None at, str label, bool setHistory=True)
 
ItemTypeVar __getitem__ (self, KeyTypeVar k)
 
int __len__ (self)
 
Iterator[KeyTypeVar__iter__ (self)
 
bool __contains__ (self, Any k)
 
None __setitem__ (self, KeyTypeVar k, ItemTypeVar x, Any at=None, str label="setitem", bool setHistory=True)
 
None __delitem__ (self, KeyTypeVar k, Any at=None, str label="delitem", bool setHistory=True)
 
 __repr__ (self)
 
 __str__ (self)
 
 __setattr__ (self, attr, value, at=None, label="assignment")
 
 __reduce__ (self)
 

Protected Member Functions

Config _config (self)
 
Dict _copy (self, Config config)
 

Protected Attributes

 _field = field
 
 _config_ = weakref.ref(config)
 
dict _dict = {}
 
Config _history = self._config._history.setdefault(self._field.name, [])
 
 _config
 

Properties

 history = property(lambda x: x._history)
 

Detailed Description

An internal mapping container.

This class emulates a `dict`, but adds validation and provenance.

Parameters
----------
config : `~lsst.pex.config.Config`
    Config to proxy.
field : `~lsst.pex.config.DictField`
    Field to use.
value : `~typing.Any`
    Value to store.
at : `list` of `~lsst.pex.config.callStack.StackFrame`
    Stack frame for history recording. Will be calculated if `None`.
label : `str`, optional
    Label to use for history recording.
setHistory : `bool`, optional
    Whether to append to the history record.

Definition at line 53 of file dictField.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.pex.config.dictField.Dict.__init__ ( self,
Config config,
DictField field,
Mapping[KeyTypeVar, ItemTypeVar] value,
* ,
list[StackFrame] | None at,
str label,
bool setHistory = True )

Definition at line 74 of file dictField.py.

83 ):
84 self._field = field
85 self._config_ = weakref.ref(config)
86 self._dict = {}
87 self._history = self._config._history.setdefault(self._field.name, [])
88 self.__doc__ = field.doc
89 if value is not None:
90 try:
91 for k in value:
92 # do not set history per-item
93 self.__setitem__(k, value[k], at=at, label=label, setHistory=False)
94 except TypeError as e:
95 msg = f"Value {value} is of incorrect type {_typeStr(value)}. Mapping type expected."
96 raise FieldValidationError(self._field, self._config, msg) from e
97 if setHistory:
98 self._history.append((dict(self._dict), at, label))
99

Member Function Documentation

◆ __contains__()

bool lsst.pex.config.dictField.Dict.__contains__ ( self,
Any k )

Definition at line 124 of file dictField.py.

124 def __contains__(self, k: Any) -> bool:
125 return k in self._dict
126

◆ __delitem__()

None lsst.pex.config.dictField.Dict.__delitem__ ( self,
KeyTypeVar k,
Any at = None,
str label = "delitem",
bool setHistory = True )

Definition at line 171 of file dictField.py.

173 ) -> None:
174 if self._config._frozen:
175 raise FieldValidationError(self._field, self._config, "Cannot modify a frozen Config")
176
177 del self._dict[k]
178 if setHistory:
179 if at is None:
180 at = getCallStack()
181 self._history.append((dict(self._dict), at, label))
182

◆ __getitem__()

ItemTypeVar lsst.pex.config.dictField.Dict.__getitem__ ( self,
KeyTypeVar k )

Definition at line 115 of file dictField.py.

115 def __getitem__(self, k: KeyTypeVar) -> ItemTypeVar:
116 return self._dict[k]
117

◆ __iter__()

Iterator[KeyTypeVar] lsst.pex.config.dictField.Dict.__iter__ ( self)

Definition at line 121 of file dictField.py.

121 def __iter__(self) -> Iterator[KeyTypeVar]:
122 return iter(self._dict)
123

◆ __len__()

int lsst.pex.config.dictField.Dict.__len__ ( self)

Definition at line 118 of file dictField.py.

118 def __len__(self) -> int:
119 return len(self._dict)
120

◆ __reduce__()

lsst.pex.config.dictField.Dict.__reduce__ ( self)

Definition at line 201 of file dictField.py.

201 def __reduce__(self):
202 raise UnexpectedProxyUsageError(
203 f"Proxy container for config field {self._field.name} cannot "
204 "be pickled; it should be converted to a built-in container before "
205 "being assigned to other objects or variables."
206 )
207
208

◆ __repr__()

lsst.pex.config.dictField.Dict.__repr__ ( self)

Definition at line 183 of file dictField.py.

183 def __repr__(self):
184 return repr(self._dict)
185

◆ __setattr__()

lsst.pex.config.dictField.Dict.__setattr__ ( self,
attr,
value,
at = None,
label = "assignment" )

Definition at line 189 of file dictField.py.

189 def __setattr__(self, attr, value, at=None, label="assignment"):
190 if hasattr(getattr(self.__class__, attr, None), "__set__"):
191 # This allows properties to work.
192 object.__setattr__(self, attr, value)
193 elif attr in self.__dict__ or attr in ["_field", "_config_", "_history", "_dict", "__doc__"]:
194 # This allows specific private attributes to work.
195 object.__setattr__(self, attr, value)
196 else:
197 # We throw everything else.
198 msg = f"{_typeStr(self._field)} has no attribute {attr}"
199 raise FieldValidationError(self._field, self._config, msg)
200

◆ __setitem__()

None lsst.pex.config.dictField.Dict.__setitem__ ( self,
KeyTypeVar k,
ItemTypeVar x,
Any at = None,
str label = "setitem",
bool setHistory = True )

Definition at line 127 of file dictField.py.

129 ) -> None:
130 if self._config._frozen:
131 msg = f"Cannot modify a frozen Config. Attempting to set item at key {k!r} to value {x}"
132 raise FieldValidationError(self._field, self._config, msg)
133
134 # validate keytype
135 k = _autocast(k, self._field.keytype)
136 if type(k) is not self._field.keytype:
137 msg = f"Key {k!r} is of type {_typeStr(k)}, expected type {_typeStr(self._field.keytype)}"
138 raise FieldValidationError(self._field, self._config, msg)
139
140 # validate itemtype
141 x = _autocast(x, self._field.itemtype)
142 if self._field.itemtype is None:
143 if type(x) not in self._field.supportedTypes and x is not None:
144 msg = f"Value {x} at key {k!r} is of invalid type {_typeStr(x)}"
145 raise FieldValidationError(self._field, self._config, msg)
146 else:
147 if type(x) is not self._field.itemtype and x is not None:
148 msg = (
149 f"Value {x} at key {k!r} is of incorrect type {_typeStr(x)}. "
150 f"Expected type {_typeStr(self._field.itemtype)}"
151 )
152 raise FieldValidationError(self._field, self._config, msg)
153
154 # validate key using keycheck
155 if self._field.keyCheck is not None and not self._field.keyCheck(k):
156 msg = f"Key {k!r} is not a valid key"
157 raise FieldValidationError(self._field, self._config, msg)
158
159 # validate item using itemcheck
160 if self._field.itemCheck is not None and not self._field.itemCheck(x):
161 msg = f"Item at key {k!r} is not a valid value: {x}"
162 raise FieldValidationError(self._field, self._config, msg)
163
164 if at is None:
165 at = getCallStack()
166
167 self._dict[k] = x
168 if setHistory:
169 self._history.append((dict(self._dict), at, label))
170

◆ __str__()

lsst.pex.config.dictField.Dict.__str__ ( self)

Definition at line 186 of file dictField.py.

186 def __str__(self):
187 return str(self._dict)
188

◆ _config()

Config lsst.pex.config.dictField.Dict._config ( self)
protected

Definition at line 101 of file dictField.py.

101 def _config(self) -> Config:
102 # Config Fields should never outlive their config class instance
103 # assert that as such here
104 value = self._config_()
105 assert value is not None
106 return value
107

◆ _copy()

Dict lsst.pex.config.dictField.Dict._copy ( self,
Config config )
protected

Reimplemented in lsst.pex.config.configDictField.ConfigDict.

Definition at line 112 of file dictField.py.

112 def _copy(self, config: Config) -> Dict:
113 return type(self)(config, self._field, self._dict.copy(), at=None, label="copy", setHistory=False)
114

Member Data Documentation

◆ _config

lsst.pex.config.dictField.Dict._config
protected

Definition at line 96 of file dictField.py.

◆ _config_

lsst.pex.config.dictField.Dict._config_ = weakref.ref(config)
protected

Definition at line 85 of file dictField.py.

◆ _dict

lsst.pex.config.dictField.Dict._dict = {}
protected

Definition at line 86 of file dictField.py.

◆ _field

lsst.pex.config.dictField.Dict._field = field
protected

Definition at line 84 of file dictField.py.

◆ _history

Config lsst.pex.config.dictField.Dict._history = self._config._history.setdefault(self._field.name, [])
protected

Definition at line 87 of file dictField.py.

Property Documentation

◆ history

lsst.pex.config.dictField.Dict.history = property(lambda x: x._history)
static

Definition at line 108 of file dictField.py.


The documentation for this class was generated from the following file: