LSST Applications g02d81e74bb+86cf3d8bc9,g180d380827+7a4e862ed4,g2079a07aa2+86d27d4dc4,g2305ad1205+e1ca1c66fa,g29320951ab+012e1474a1,g295015adf3+341ea1ce94,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g33d1c0ed96+0e5473021a,g3a166c0a6a+0e5473021a,g3ddfee87b4+c429d67c83,g48712c4677+f88676dd22,g487adcacf7+27e1e21933,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+b41db86c35,g5a732f18d5+53520f316c,g64a986408d+86cf3d8bc9,g858d7b2824+86cf3d8bc9,g8a8a8dda67+585e252eca,g99cad8db69+84912a7fdc,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+a2b54eae19,gb0e22166c9+60f28cb32d,gba4ed39666+c2a2e4ac27,gbb8dafda3b+6681f309db,gc120e1dc64+f0fcc2f6d8,gc28159a63d+0e5473021a,gcf0d15dbbd+c429d67c83,gdaeeff99f8+f9a426f77a,ge6526c86ff+0433e6603d,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gff1a9f87cc+86cf3d8bc9,w.2024.17
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Properties | List of all members
lsst.pex.config.configChoiceField.ConfigInstanceDict Class Reference
Inheritance diagram for lsst.pex.config.configChoiceField.ConfigInstanceDict:
lsst.pex.config.config.Config lsst.pex.config.config.ConfigMeta lsst.pex.config.configChoiceField.ConfigChoiceField lsst.pex.config.registry.RegistryInstanceDict lsst.pex.config.registry.RegistryField

Public Member Functions

 __init__ (self, config, field)
 
 types (self)
 
 __contains__ (self, k)
 
 __len__ (self)
 
 __iter__ (self)
 
 __getitem__ (self, k, at=None, label="default")
 
 __setitem__ (self, k, value, at=None, label="assignment")
 
 __setattr__ (self, attr, value, at=None, label="assignment")
 
 freeze (self)
 
 __reduce__ (self)
 

Public Attributes

 types
 

Protected Member Functions

 _setSelection (self, value, at=None, label="assignment")
 
 _getNames (self)
 
 _setNames (self, value)
 
 _delNames (self)
 
 _getName (self)
 
 _setName (self, value)
 
 _delName (self)
 
 _getActive (self)
 
 _rename (self, fullname)
 

Protected Attributes

 _dict
 
 _selection
 
 _config
 
 _field
 
 _history
 
 _typemap
 

Properties

 names = property(_getNames, _setNames, _delNames)
 
 name = property(_getName, _setName, _delName)
 
 active = property(_getActive)
 

Detailed Description

Dictionary of instantiated configs, used to populate a
`~lsst.pex.config.ConfigChoiceField`.

Parameters
----------
config : `lsst.pex.config.Config`
    A configuration instance.
field : `lsst.pex.config.Field`-type
    A configuration field. Note that the `lsst.pex.config.Field.fieldmap`
    attribute must provide key-based access to configuration classes,
    (that is, ``typemap[name]``).

Definition at line 166 of file configChoiceField.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.pex.config.configChoiceField.ConfigInstanceDict.__init__ ( self,
config,
field )

Reimplemented from lsst.pex.config.config.ConfigMeta.

Reimplemented in lsst.pex.config.registry.RegistryInstanceDict, lsst.pex.config.registry.RegistryField, and lsst.pex.config.configChoiceField.ConfigChoiceField.

Definition at line 180 of file configChoiceField.py.

180 def __init__(self, config, field):
181 collections.abc.Mapping.__init__(self)
182 self._dict = {}
183 self._selection = None
184 self._config = config
185 self._field = field
186 self._history = config._history.setdefault(field.name, [])
187 self.__doc__ = field.doc
188 self._typemap = None
189

Member Function Documentation

◆ __contains__()

lsst.pex.config.configChoiceField.ConfigInstanceDict.__contains__ ( self,
name )
Return `True` if the specified field exists in this config.

Parameters
----------
name : `str`
    Field name to test for.

Returns
-------
in : `bool`
    `True` if the specified field exists in the config.

Reimplemented from lsst.pex.config.config.Config.

Definition at line 194 of file configChoiceField.py.

194 def __contains__(self, k):
195 return k in self.types
196

◆ __getitem__()

lsst.pex.config.configChoiceField.ConfigInstanceDict.__getitem__ ( self,
k,
at = None,
label = "default" )

Definition at line 290 of file configChoiceField.py.

290 def __getitem__(self, k, at=None, label="default"):
291 try:
292 value = self._dict[k]
293 except KeyError:
294 try:
295 dtype = self.types[k]
296 except Exception:
297 raise FieldValidationError(
298 self._field, self._config, "Unknown key %r in Registry/ConfigChoiceField" % k
299 )
300 name = _joinNamePath(self._config._name, self._field.name, k)
301 if at is None:
302 at = getCallStack()
303 at.insert(0, dtype._source)
304 value = self._dict.setdefault(k, dtype(__name=name, __at=at, __label=label))
305 return value
306

◆ __iter__()

lsst.pex.config.configChoiceField.ConfigInstanceDict.__iter__ ( self)
Iterate over fields.

Reimplemented from lsst.pex.config.config.Config.

Definition at line 200 of file configChoiceField.py.

200 def __iter__(self):
201 return iter(self.types)
202

◆ __len__()

lsst.pex.config.configChoiceField.ConfigInstanceDict.__len__ ( self)

Definition at line 197 of file configChoiceField.py.

197 def __len__(self):
198 return len(self.types)
199

◆ __reduce__()

lsst.pex.config.configChoiceField.ConfigInstanceDict.__reduce__ ( self)
Reduction for pickling (function with arguments to reproduce).

We need to condense and reconstitute the `~lsst.pex.config.Config`,
since it may contain lambdas (as the ``check`` elements) that cannot
be pickled.

Reimplemented from lsst.pex.config.config.Config.

Definition at line 375 of file configChoiceField.py.

375 def __reduce__(self):
376 raise UnexpectedProxyUsageError(
377 f"Proxy container for config field {self._field.name} cannot "
378 "be pickled; it should be converted to a built-in container before "
379 "being assigned to other objects or variables."
380 )
381
382

◆ __setattr__()

lsst.pex.config.configChoiceField.ConfigInstanceDict.__setattr__ ( self,
attr,
value,
at = None,
label = "assignment" )
Set an attribute (such as a field's value).

Notes
-----
Unlike normal Python objects, `~lsst.pex.config.Config` objects are
locked such that no additional attributes nor properties may be added
to them dynamically.

Although this is not the standard Python behavior, it helps to protect
users from accidentally mispelling a field name, or trying to set a
non-existent field.

Reimplemented from lsst.pex.config.config.Config.

Reimplemented in lsst.pex.config.registry.RegistryInstanceDict.

Definition at line 343 of file configChoiceField.py.

343 def __setattr__(self, attr, value, at=None, label="assignment"):
344 if hasattr(getattr(self.__class__, attr, None), "__set__"):
345 # This allows properties to work.
346 object.__setattr__(self, attr, value)
347 elif attr in self.__dict__ or attr in [
348 "_history",
349 "_field",
350 "_config",
351 "_dict",
352 "_selection",
353 "__doc__",
354 "_typemap",
355 ]:
356 # This allows specific private attributes to work.
357 object.__setattr__(self, attr, value)
358 else:
359 # We throw everything else.
360 msg = f"{_typeStr(self._field)} has no attribute {attr}"
361 raise FieldValidationError(self._field, self._config, msg)
362

◆ __setitem__()

lsst.pex.config.configChoiceField.ConfigInstanceDict.__setitem__ ( self,
k,
value,
at = None,
label = "assignment" )

Definition at line 307 of file configChoiceField.py.

307 def __setitem__(self, k, value, at=None, label="assignment"):
308 if self._config._frozen:
309 raise FieldValidationError(self._field, self._config, "Cannot modify a frozen Config")
310
311 try:
312 dtype = self.types[k]
313 except Exception:
314 raise FieldValidationError(self._field, self._config, "Unknown key %r" % k)
315
316 if value != dtype and type(value) is not dtype:
317 msg = "Value {} at key {} is of incorrect type {}. Expected type {}".format(
318 value,
319 k,
320 _typeStr(value),
321 _typeStr(dtype),
322 )
323 raise FieldValidationError(self._field, self._config, msg)
324
325 if at is None:
326 at = getCallStack()
327 name = _joinNamePath(self._config._name, self._field.name, k)
328 oldValue = self._dict.get(k, None)
329 if oldValue is None:
330 if value == dtype:
331 self._dict[k] = value(__name=name, __at=at, __label=label)
332 else:
333 self._dict[k] = dtype(__name=name, __at=at, __label=label, **value._storage)
334 else:
335 if value == dtype:
336 value = value()
337 oldValue.update(__at=at, __label=label, **value._storage)
338

◆ _delName()

lsst.pex.config.configChoiceField.ConfigInstanceDict._delName ( self)
protected

Definition at line 255 of file configChoiceField.py.

255 def _delName(self):
256 if self._field.multi:
257 raise FieldValidationError(
258 self._field, self._config, "Multi-selection field has no attribute 'name'"
259 )
260 self._selection = None
261

◆ _delNames()

lsst.pex.config.configChoiceField.ConfigInstanceDict._delNames ( self)
protected

Definition at line 234 of file configChoiceField.py.

234 def _delNames(self):
235 if not self._field.multi:
236 raise FieldValidationError(
237 self._field, self._config, "Single-selection field has no attribute 'names'"
238 )
239 self._selection = None
240

◆ _getActive()

lsst.pex.config.configChoiceField.ConfigInstanceDict._getActive ( self)
protected

Definition at line 274 of file configChoiceField.py.

274 def _getActive(self):
275 if self._selection is None:
276 return None
277
278 if self._field.multi:
279 return [self[c] for c in self._selection]
280 else:
281 return self[self._selection]
282

◆ _getName()

lsst.pex.config.configChoiceField.ConfigInstanceDict._getName ( self)
protected

Definition at line 241 of file configChoiceField.py.

241 def _getName(self):
242 if self._field.multi:
243 raise FieldValidationError(
244 self._field, self._config, "Multi-selection field has no attribute 'name'"
245 )
246 return self._selection
247

◆ _getNames()

lsst.pex.config.configChoiceField.ConfigInstanceDict._getNames ( self)
protected

Definition at line 220 of file configChoiceField.py.

220 def _getNames(self):
221 if not self._field.multi:
222 raise FieldValidationError(
223 self._field, self._config, "Single-selection field has no attribute 'names'"
224 )
225 return self._selection
226

◆ _rename()

lsst.pex.config.configChoiceField.ConfigInstanceDict._rename ( self,
name )
protected
Rename this config object in its parent `~lsst.pex.config.Config`.

Parameters
----------
name : `str`
    New name for this config in its parent `~lsst.pex.config.Config`.

Notes
-----
This method uses the `~lsst.pex.config.Field.rename` method of
individual `lsst.pex.config.Field` instances.
`lsst.pex.config.Field` subclasses may need to implement a ``rename``
method for *this* method to work.

See Also
--------
lsst.pex.config.Field.rename

Reimplemented from lsst.pex.config.config.Config.

Definition at line 339 of file configChoiceField.py.

339 def _rename(self, fullname):
340 for k, v in self._dict.items():
341 v._rename(_joinNamePath(name=fullname, index=k))
342
std::vector< SchemaItem< Flag > > * items

◆ _setName()

lsst.pex.config.configChoiceField.ConfigInstanceDict._setName ( self,
value )
protected

Definition at line 248 of file configChoiceField.py.

248 def _setName(self, value):
249 if self._field.multi:
250 raise FieldValidationError(
251 self._field, self._config, "Multi-selection field has no attribute 'name'"
252 )
253 self._setSelection(value)
254

◆ _setNames()

lsst.pex.config.configChoiceField.ConfigInstanceDict._setNames ( self,
value )
protected

Definition at line 227 of file configChoiceField.py.

227 def _setNames(self, value):
228 if not self._field.multi:
229 raise FieldValidationError(
230 self._field, self._config, "Single-selection field has no attribute 'names'"
231 )
232 self._setSelection(value)
233

◆ _setSelection()

lsst.pex.config.configChoiceField.ConfigInstanceDict._setSelection ( self,
value,
at = None,
label = "assignment" )
protected

Definition at line 203 of file configChoiceField.py.

203 def _setSelection(self, value, at=None, label="assignment"):
204 if self._config._frozen:
205 raise FieldValidationError(self._field, self._config, "Cannot modify a frozen Config")
206
207 if at is None:
208 at = getCallStack(1)
209
210 if value is None:
211 self._selection = None
212 elif self._field.multi:
213 self._selection = SelectionSet(self, value, setHistory=False)
214 else:
215 if value not in self._dict:
216 self.__getitem__(value, at=at) # just invoke __getitem__ to make sure it's present
217 self._selection = value
218 self._history.append((value, at, label))
219

◆ freeze()

lsst.pex.config.configChoiceField.ConfigInstanceDict.freeze ( self)
Freeze the config.

Invoking this freeze method will create a local copy of the field
attribute's typemap. This decouples this instance dict from the
underlying objects type map ensuring that and subsequent changes to the
typemap will not be reflected in this instance (i.e imports adding
additional registry entries).

Reimplemented from lsst.pex.config.config.Config.

Reimplemented in lsst.pex.config.configChoiceField.ConfigChoiceField.

Definition at line 363 of file configChoiceField.py.

363 def freeze(self):
364 """Freeze the config.
365
366 Invoking this freeze method will create a local copy of the field
367 attribute's typemap. This decouples this instance dict from the
368 underlying objects type map ensuring that and subsequent changes to the
369 typemap will not be reflected in this instance (i.e imports adding
370 additional registry entries).
371 """
372 if self._typemap is None:
373 self._typemap = copy.deepcopy(self.types)
374

◆ types()

lsst.pex.config.configChoiceField.ConfigInstanceDict.types ( self)

Definition at line 191 of file configChoiceField.py.

191 def types(self):
192 return self._typemap if self._typemap is not None else self._field.typemap
193

Member Data Documentation

◆ _config

lsst.pex.config.configChoiceField.ConfigInstanceDict._config
protected

Definition at line 184 of file configChoiceField.py.

◆ _dict

lsst.pex.config.configChoiceField.ConfigInstanceDict._dict
protected

Definition at line 182 of file configChoiceField.py.

◆ _field

lsst.pex.config.configChoiceField.ConfigInstanceDict._field
protected

Definition at line 185 of file configChoiceField.py.

◆ _history

lsst.pex.config.configChoiceField.ConfigInstanceDict._history
protected

Definition at line 186 of file configChoiceField.py.

◆ _selection

lsst.pex.config.configChoiceField.ConfigInstanceDict._selection
protected

Definition at line 183 of file configChoiceField.py.

◆ _typemap

lsst.pex.config.configChoiceField.ConfigInstanceDict._typemap
protected

Definition at line 188 of file configChoiceField.py.

◆ types

lsst.pex.config.configChoiceField.ConfigInstanceDict.types

Definition at line 198 of file configChoiceField.py.

Property Documentation

◆ active

lsst.pex.config.configChoiceField.ConfigInstanceDict.active = property(_getActive)
static

Definition at line 283 of file configChoiceField.py.

◆ name

lsst.pex.config.configChoiceField.ConfigInstanceDict.name = property(_getName, _setName, _delName)
static

Definition at line 268 of file configChoiceField.py.

◆ names

lsst.pex.config.configChoiceField.ConfigInstanceDict.names = property(_getNames, _setNames, _delNames)
static

Definition at line 262 of file configChoiceField.py.


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