LSST Applications g0265f82a02+d6b5cd48b5,g02d81e74bb+a41d3748ce,g1470d8bcf6+6be6c9203b,g2079a07aa2+14824f138e,g212a7c68fe+a4f2ea4efa,g2305ad1205+72971fe858,g295015adf3+ab2c85acae,g2bbee38e9b+d6b5cd48b5,g337abbeb29+d6b5cd48b5,g3ddfee87b4+31b3a28dff,g487adcacf7+082e807817,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+b2918d57ae,g5a732f18d5+66d966b544,g64a986408d+a41d3748ce,g858d7b2824+a41d3748ce,g8a8a8dda67+a6fc98d2e7,g99cad8db69+7fe4acdf18,g9ddcbc5298+d4bad12328,ga1e77700b3+246acaaf9c,ga8c6da7877+84af8b3ff8,gb0e22166c9+3863383f4c,gb6a65358fc+d6b5cd48b5,gba4ed39666+9664299f35,gbb8dafda3b+d8d527deb2,gc07e1c2157+b2dbe6b631,gc120e1dc64+61440b2abb,gc28159a63d+d6b5cd48b5,gcf0d15dbbd+31b3a28dff,gdaeeff99f8+a38ce5ea23,ge6526c86ff+39927bb362,ge79ae78c31+d6b5cd48b5,gee10cc3b42+a6fc98d2e7,gf1cff7945b+a41d3748ce,v24.1.5.rc1
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.registry.RegistryInstanceDict Class Reference
Inheritance diagram for lsst.pex.config.registry.RegistryInstanceDict:
lsst.pex.config.configChoiceField.ConfigInstanceDict lsst.pex.config.config.Config lsst.pex.config.config.ConfigMeta

Public Member Functions

 __init__ (self, config, field)
 
 apply (self, *args, **kwargs)
 
 apply_with (self, selection, *args, **kwargs)
 
 __setattr__ (self, attr, value)
 

Public Attributes

 registry
 

Protected Member Functions

 _getTarget (self)
 
 _getTargets (self)
 

Protected Attributes

 _field
 
 _config
 
 _selection
 

Properties

 target = property(_getTarget)
 
 targets = property(_getTargets)
 

Detailed Description

Dictionary of instantiated configs, used to populate a `RegistryField`.

Parameters
----------
config : `lsst.pex.config.Config`
    Configuration instance.
field : `RegistryField`
    Configuration field.

Definition at line 244 of file registry.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.pex.config.registry.RegistryInstanceDict.__init__ ( self,
config,
field )

Reimplemented from lsst.pex.config.configChoiceField.ConfigInstanceDict.

Definition at line 255 of file registry.py.

255 def __init__(self, config, field):
256 ConfigInstanceDict.__init__(self, config, field)
257 self.registry = field.registry
258

Member Function Documentation

◆ __setattr__()

lsst.pex.config.registry.RegistryInstanceDict.__setattr__ ( self,
attr,
value )
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.configChoiceField.ConfigInstanceDict.

Definition at line 333 of file registry.py.

333 def __setattr__(self, attr, value):
334 if attr == "registry":
335 object.__setattr__(self, attr, value)
336 else:
337 ConfigInstanceDict.__setattr__(self, attr, value)
338
339

◆ _getTarget()

lsst.pex.config.registry.RegistryInstanceDict._getTarget ( self)
protected

Definition at line 259 of file registry.py.

259 def _getTarget(self):
260 if self._field.multi:
261 raise FieldValidationError(
262 self._field, self._config, "Multi-selection field has no attribute 'target'"
263 )
264 return self.types.registry[self._selection]
265

◆ _getTargets()

lsst.pex.config.registry.RegistryInstanceDict._getTargets ( self)
protected

Definition at line 268 of file registry.py.

268 def _getTargets(self):
269 if not self._field.multi:
270 raise FieldValidationError(
271 self._field, self._config, "Single-selection field has no attribute 'targets'"
272 )
273 return [self.types.registry[c] for c in self._selection]
274

◆ apply()

lsst.pex.config.registry.RegistryInstanceDict.apply ( self,
* args,
** kwargs )
Call the active target(s) with the active config as a keyword arg.

Parameters
----------
*args, **kwargs : `~typing.Any
    Additional arguments will be passed on to the configurable
    target(s).

Returns
-------
result
    If this is a single-selection field, the return value from calling
    the target. If this is a multi-selection field, a list thereof.

Definition at line 277 of file registry.py.

277 def apply(self, *args, **kwargs):
278 """Call the active target(s) with the active config as a keyword arg.
279
280 Parameters
281 ----------
282 *args, **kwargs : `~typing.Any
283 Additional arguments will be passed on to the configurable
284 target(s).
285
286 Returns
287 -------
288 result
289 If this is a single-selection field, the return value from calling
290 the target. If this is a multi-selection field, a list thereof.
291 """
292 if self.active is None:
293 if self._field._on_none is not None:
294 return self._field._on_none(self, *args, **kwargs)
295 msg = "No selection has been made. Options: %s" % " ".join(self.types.registry.keys())
296 raise FieldValidationError(self._field, self._config, msg)
297 return self.apply_with(self._selection, *args, **kwargs)
298

◆ apply_with()

lsst.pex.config.registry.RegistryInstanceDict.apply_with ( self,
selection,
* args,
** kwargs )
Call named target(s) with the corresponding config as a keyword
arg.

Parameters
----------
selection : `str` or `~collections.abc.Iterable` [ `str` ]
    Name or names of targets, depending on whether ``multi=True``.
*args, **kwargs
    Additional arguments will be passed on to the configurable
    target(s).

Returns
-------
result
    If this is a single-selection field, the return value from calling
    the target. If this is a multi-selection field, a list thereof.

Notes
-----
This method ignores the current selection in the ``name`` or ``names``
attribute, which is usually not what you want.  This method is most
useful in ``on_none`` callbacks provided at field construction, which
allow a context-dependent default to be used when no selection is
configured.

Definition at line 299 of file registry.py.

299 def apply_with(self, selection, *args, **kwargs):
300 """Call named target(s) with the corresponding config as a keyword
301 arg.
302
303 Parameters
304 ----------
305 selection : `str` or `~collections.abc.Iterable` [ `str` ]
306 Name or names of targets, depending on whether ``multi=True``.
307 *args, **kwargs
308 Additional arguments will be passed on to the configurable
309 target(s).
310
311 Returns
312 -------
313 result
314 If this is a single-selection field, the return value from calling
315 the target. If this is a multi-selection field, a list thereof.
316
317 Notes
318 -----
319 This method ignores the current selection in the ``name`` or ``names``
320 attribute, which is usually not what you want. This method is most
321 useful in ``on_none`` callbacks provided at field construction, which
322 allow a context-dependent default to be used when no selection is
323 configured.
324 """
325 if self._field.multi:
326 retvals = []
327 for c in selection:
328 retvals.append(self.types.registry[c](*args, config=self[c], **kwargs))
329 return retvals
330 else:
331 return self.types.registry[selection](*args, config=self[selection], **kwargs)
332

Member Data Documentation

◆ _config

lsst.pex.config.registry.RegistryInstanceDict._config
protected

Definition at line 262 of file registry.py.

◆ _field

lsst.pex.config.registry.RegistryInstanceDict._field
protected

Definition at line 262 of file registry.py.

◆ _selection

lsst.pex.config.registry.RegistryInstanceDict._selection
protected

Definition at line 297 of file registry.py.

◆ registry

lsst.pex.config.registry.RegistryInstanceDict.registry

Definition at line 257 of file registry.py.

Property Documentation

◆ target

lsst.pex.config.registry.RegistryInstanceDict.target = property(_getTarget)
static

Definition at line 266 of file registry.py.

◆ targets

lsst.pex.config.registry.RegistryInstanceDict.targets = property(_getTargets)
static

Definition at line 275 of file registry.py.


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