LSST Applications 24.1.6,g063fba187b+56b85ce14a,g0f08755f38+df8a265115,g12f32b3c4e+891a09f10d,g1524ad2192+7a5d7b3fbd,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g28da252d5a+07cb1400be,g2bbee38e9b+ae03bbfc84,g2bc492864f+ae03bbfc84,g3156d2b45e+6e55a43351,g347aa1857d+ae03bbfc84,g35bb328faa+a8ce1bb630,g3a166c0a6a+ae03bbfc84,g3e281a1b8c+c5dd892a6c,g414038480c+6b9177ef31,g41af890bb2+8f257c4c0b,g781aacb6e4+a8ce1bb630,g7af13505b9+7137b3b17d,g80478fca09+6df6903293,g82479be7b0+091ce1d07f,g858d7b2824+df8a265115,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,g9726552aa6+414189b318,ga5288a1d22+4a2bca08d7,gacef1a1666+c9a8ff65f4,gb58c049af0+d64f4d3760,gbcfae0f0a0+de1d42d831,gc28159a63d+ae03bbfc84,gcf0d15dbbd+72117bf34e,gda6a2b7d83+72117bf34e,gdaeeff99f8+1711a396fd,ge500cccec5+c8c9c9af63,ge79ae78c31+ae03bbfc84,gf0baf85859+c1f95f4921,gfa517265be+df8a265115,gfa999e8aa5+17cd334064,gfb92a5be7c+df8a265115
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, f"Unknown key {k!r} in Registry/ConfigChoiceField"
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 373 of file configChoiceField.py.

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

◆ __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 341 of file configChoiceField.py.

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

◆ __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, f"Unknown key {k!r}")
315
316 if value != dtype and type(value) is not dtype:
317 msg = (
318 f"Value {value} at key {k} is of incorrect type {_typeStr(value)}. "
319 f"Expected type {_typeStr(dtype)}"
320 )
321 raise FieldValidationError(self._field, self._config, msg)
322
323 if at is None:
324 at = getCallStack()
325 name = _joinNamePath(self._config._name, self._field.name, k)
326 oldValue = self._dict.get(k, None)
327 if oldValue is None:
328 if value == dtype:
329 self._dict[k] = value(__name=name, __at=at, __label=label)
330 else:
331 self._dict[k] = dtype(__name=name, __at=at, __label=label, **value._storage)
332 else:
333 if value == dtype:
334 value = value()
335 oldValue.update(__at=at, __label=label, **value._storage)
336

◆ _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 337 of file configChoiceField.py.

337 def _rename(self, fullname):
338 for k, v in self._dict.items():
339 v._rename(_joinNamePath(name=fullname, index=k))
340
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 361 of file configChoiceField.py.

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

◆ 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: