lsst.pex.config  18.1.0-1-gc037db8+3
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst.pex.config.configChoiceField.ConfigChoiceField Class Reference
Inheritance diagram for lsst.pex.config.configChoiceField.ConfigChoiceField:
lsst.pex.config.config.Field lsst.pex.config.registry.RegistryField

Public Member Functions

def __init__ (self, doc, typemap, default=None, optional=False, multi=False, deprecated=None)
 
def __get__ (self, instance, owner=None)
 
def __set__ (self, instance, value, at=None, label="assignment")
 
def rename (self, instance)
 
def validate (self, instance)
 
def toDict (self, instance)
 
def freeze (self, instance)
 
def save (self, outfile, instance)
 
def __deepcopy__ (self, memo)
 
def __get__ (self, instance, owner=None, at=None, label="default")
 
def __delete__ (self, instance, at=None, label='deletion')
 

Public Attributes

 typemap
 
 multi
 
 dtype
 
 doc
 
 deprecated
 
 default
 
 check
 
 optional
 
 source
 

Static Public Attributes

 instanceDictClass = ConfigInstanceDict
 
 supportedTypes = set((str, bool, float, int, complex))
 

Detailed Description

A configuration field (`~lsst.pex.config.Field` subclass) that allows a
user to choose from a set of `~lsst.pex.config.Config` types.

Parameters
----------
doc : `str`
    Documentation string for the field.
typemap : `dict`-like
    A mapping between keys and `~lsst.pex.config.Config`-types as values.
    See *Examples* for details.
default : `str`, optional
    The default configuration name.
optional : `bool`, optional
    When `False`, `lsst.pex.config.Config.validate` will fail if the
    field's value is `None`.
multi : `bool`, optional
    If `True`, the field allows multiple selections. In this case, set the
    selections by assigning a sequence to the ``names`` attribute of the
    field.

    If `False`, the field allows only a single selection. In this case,
    set the active config by assigning the config's key from the
    ``typemap`` to the field's ``name`` attribute (see *Examples*).
deprecated : None or `str`, optional
    A description of why this Field is deprecated, including removal date.
    If not None, the string is appended to the docstring for this Field.

See also
--------
ChoiceField
ConfigDictField
ConfigField
ConfigurableField
DictField
Field
ListField
RangeField
RegistryField

Notes
-----
``ConfigChoiceField`` instances can allow either single selections or
multiple selections, depending on the ``multi`` parameter. For
single-selection fields, set the selection with the ``name`` attribute.
For multi-selection fields, set the selection though the ``names``
attribute.

This field is validated only against the active selection. If the
``active`` attribute is `None` and the field is not optional, validation
will fail.

When saving a configuration with a ``ConfigChoiceField``, the entire set is
saved, as well as the active selection.

Examples
--------
While the ``typemap`` is shared by all instances of the field, each
instance of the field has its own instance of a particular sub-config type.

For example, ``AaaConfig`` is a config object

>>> from lsst.pex.config import Config, ConfigChoiceField, Field
>>> class AaaConfig(Config):
...     somefield = Field("doc", int)
...

The ``MyConfig`` config has a ``ConfigChoiceField`` field called ``choice``
that maps the ``AaaConfig`` type to the ``"AAA"`` key:

>>> TYPEMAP = {"AAA", AaaConfig}
>>> class MyConfig(Config):
...     choice = ConfigChoiceField("doc for choice", TYPEMAP)
...

Creating an instance of ``MyConfig``:

>>> instance = MyConfig()

Setting value of the field ``somefield`` on the "AAA" key of the ``choice``
field:

>>> instance.choice['AAA'].somefield = 5

**Selecting the active configuration**

Make the ``"AAA"`` key the active configuration value for the ``choice``
field:

>>> instance.choice = "AAA"

Alternatively, the last line can be written:

>>> instance.choice.name = "AAA"

(If the config instance allows multiple selections, you'd assign a sequence
to the ``names`` attribute instead.)

``ConfigChoiceField`` instances also allow multiple values of the same type:

>>> TYPEMAP["CCC"] = AaaConfig
>>> TYPEMAP["BBB"] = AaaConfig

Definition at line 306 of file configChoiceField.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.pex.config.configChoiceField.ConfigChoiceField.__init__ (   self,
  doc,
  typemap,
  default = None,
  optional = False,
  multi = False,
  deprecated = None 
)

Definition at line 412 of file configChoiceField.py.

Member Function Documentation

◆ __deepcopy__()

def lsst.pex.config.configChoiceField.ConfigChoiceField.__deepcopy__ (   self,
  memo 
)
Customize deep-copying, because we always want a reference to the
original typemap.

WARNING: this must be overridden by subclasses if they change the
constructor signature!

Definition at line 509 of file configChoiceField.py.

◆ __delete__()

def lsst.pex.config.config.Field.__delete__ (   self,
  instance,
  at = None,
  label = 'deletion' 
)
inherited
Delete an attribute from a `lsst.pex.config.Config` instance.

Parameters
----------
instance : `lsst.pex.config.Config`
    The config instance that contains this field.
at : `list` of `lsst.pex.config.callStack.StackFrame`
    The call stack (created by
    `lsst.pex.config.callStack.getCallStack`).
label : `str`, optional
    Event label for the history.

Notes
-----
This is invoked by the owning `~lsst.pex.config.Config` object and
should not be called directly.

Definition at line 563 of file config.py.

◆ __get__() [1/2]

def lsst.pex.config.configChoiceField.ConfigChoiceField.__get__ (   self,
  instance,
  owner = None 
)

Definition at line 431 of file configChoiceField.py.

◆ __get__() [2/2]

def lsst.pex.config.config.Field.__get__ (   self,
  instance,
  owner = None,
  at = None,
  label = "default" 
)
inherited
Define how attribute access should occur on the Config instance
This is invoked by the owning config object and should not be called
directly

When the field attribute is accessed on a Config class object, it
returns the field object itself in order to allow inspection of
Config classes.

When the field attribute is access on a config instance, the actual
value described by the field (and held by the Config instance) is
returned.

Definition at line 488 of file config.py.

◆ __set__()

def lsst.pex.config.configChoiceField.ConfigChoiceField.__set__ (   self,
  instance,
  value,
  at = None,
  label = "assignment" 
)

Definition at line 437 of file configChoiceField.py.

◆ freeze()

def lsst.pex.config.configChoiceField.ConfigChoiceField.freeze (   self,
  instance 
)

Definition at line 484 of file configChoiceField.py.

◆ rename()

def lsst.pex.config.configChoiceField.ConfigChoiceField.rename (   self,
  instance 
)

Definition at line 451 of file configChoiceField.py.

◆ save()

def lsst.pex.config.configChoiceField.ConfigChoiceField.save (   self,
  outfile,
  instance 
)

Definition at line 499 of file configChoiceField.py.

◆ toDict()

def lsst.pex.config.configChoiceField.ConfigChoiceField.toDict (   self,
  instance 
)

Definition at line 468 of file configChoiceField.py.

◆ validate()

def lsst.pex.config.configChoiceField.ConfigChoiceField.validate (   self,
  instance 
)

Definition at line 456 of file configChoiceField.py.

Member Data Documentation

◆ check

lsst.pex.config.config.Field.check
inherited

Definition at line 305 of file config.py.

◆ default

lsst.pex.config.config.Field.default
inherited

Definition at line 301 of file config.py.

◆ deprecated

lsst.pex.config.config.Field.deprecated
inherited

Definition at line 292 of file config.py.

◆ doc

lsst.pex.config.config.Field.doc
inherited

Definition at line 288 of file config.py.

◆ dtype

lsst.pex.config.config.Field.dtype
inherited

Definition at line 281 of file config.py.

◆ instanceDictClass

lsst.pex.config.configChoiceField.ConfigChoiceField.instanceDictClass = ConfigInstanceDict
static

Definition at line 410 of file configChoiceField.py.

◆ multi

lsst.pex.config.configChoiceField.ConfigChoiceField.multi

Definition at line 417 of file configChoiceField.py.

◆ optional

lsst.pex.config.config.Field.optional
inherited

Definition at line 309 of file config.py.

◆ source

lsst.pex.config.config.Field.source
inherited

Definition at line 316 of file config.py.

◆ supportedTypes

lsst.pex.config.config.Field.supportedTypes = set((str, bool, float, int, complex))
staticinherited

Definition at line 266 of file config.py.

◆ typemap

lsst.pex.config.configChoiceField.ConfigChoiceField.typemap

Definition at line 416 of file configChoiceField.py.


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