lsst.pex.config  16.0-3-g9645794+8
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst.pex.config.config.Field Class Reference
Inheritance diagram for lsst.pex.config.config.Field:
lsst.pex.config.choiceField.ChoiceField lsst.pex.config.configChoiceField.ConfigChoiceField lsst.pex.config.configField.ConfigField lsst.pex.config.configurableField.ConfigurableField lsst.pex.config.dictField.DictField lsst.pex.config.listField.ListField lsst.pex.config.rangeField.RangeField lsst.pex.config.registry.RegistryField lsst.pex.config.configDictField.ConfigDictField

Public Member Functions

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

Public Attributes

 dtype
 
 doc
 
 default
 
 check
 
 optional
 
 source
 

Static Public Attributes

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

Detailed Description

A field in a a Config.

Instances of Field should be class attributes of Config subclasses:
Field only supports basic data types (int, float, complex, bool, str)

class Example(Config):
    myInt = Field(int, "an integer field!", default=0)

Definition at line 142 of file config.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.pex.config.config.Field.__init__ (   self,
  doc,
  dtype,
  default = None,
  check = None,
  optional = False 
)
Initialize a Field.

dtype ------ Data type for the field.
doc -------- Documentation for the field.
default ---- A default value for the field.
check ------ A callable to be called with the field value that returns
     False if the value is invalid.  More complex inter-field
     validation can be written as part of Config validate()
     method; this will be ignored if set to None.
optional --- When False, Config validate() will fail if value is None

Definition at line 155 of file config.py.

Member Function Documentation

◆ __delete__()

def lsst.pex.config.config.Field.__delete__ (   self,
  instance,
  at = None,
  label = 'deletion' 
)
Describe how attribute deletion should occur on the Config instance.
This is invoked by the owning config object and should not be called
directly

Definition at line 329 of file config.py.

◆ __get__()

def lsst.pex.config.config.Field.__get__ (   self,
  instance,
  owner = None,
  at = None,
  label = "default" 
)
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 272 of file config.py.

◆ __set__()

def lsst.pex.config.config.Field.__set__ (   self,
  instance,
  value,
  at = None,
  label = 'assignment' 
)
Describe how attribute setting should occur on the config instance.
This is invoked by the owning config object and should not be called
directly

Derived Field classes may need to override the behavior. When overriding
__set__, Field authors should follow the following rules:
* Do not allow modification of frozen configs
* Validate the new value *BEFORE* modifying the field. Except if the
    new value is None. None is special and no attempt should be made to
    validate it until Config.validate is called.
* Do not modify the Config instance to contain invalid values.
* If the field is modified, update the history of the field to reflect the
    changes

In order to decrease the need to implement this method in derived Field
types, value validation is performed in the method _validateValue. If
only the validation step differs in the derived Field, it is simpler to
implement _validateValue than to re-implement __set__. More complicated
behavior, however, may require a reimplementation.

Definition at line 291 of file config.py.

◆ freeze()

def lsst.pex.config.config.Field.freeze (   self,
  instance 
)
Make this field read-only.
Only important for fields which hold sub-configs.
Fields which hold subconfigs should freeze each sub-config.

Definition at line 211 of file config.py.

◆ rename()

def lsst.pex.config.config.Field.rename (   self,
  instance 
)
Rename an instance of this field, not the field itself.
This is invoked by the owning config object and should not be called
directly

Only useful for fields which hold sub-configs.
Fields which hold subconfigs should rename each sub-config with
the full field name as generated by _joinNamePath

Definition at line 186 of file config.py.

◆ save()

def lsst.pex.config.config.Field.save (   self,
  outfile,
  instance 
)
Saves an instance of this field to file.
This is invoked by the owning config object, and should not be called
directly

outfile ---- an open output stream.

Definition at line 238 of file config.py.

◆ toDict()

def lsst.pex.config.config.Field.toDict (   self,
  instance 
)
Convert the field value so that it can be set as the value of an item
in a dict.
This is invoked by the owning config object and should not be called
directly

Simple values are passed through. Complex data structures must be
manipulated. For example, a field holding a sub-config should, instead
of the subconfig object, return a dict where the keys are the field
names in the subconfig, and the values are the field values in the
subconfig.

Definition at line 257 of file config.py.

◆ validate()

def lsst.pex.config.config.Field.validate (   self,
  instance 
)
Base validation for any field.
Ensures that non-optional fields are not None.
Ensures type correctness
Ensures that user-provided check function is valid
Most derived Field types should call Field.validate if they choose
to re-implement validate

Definition at line 198 of file config.py.

Member Data Documentation

◆ check

lsst.pex.config.config.Field.check

Definition at line 182 of file config.py.

◆ default

lsst.pex.config.config.Field.default

Definition at line 181 of file config.py.

◆ doc

lsst.pex.config.config.Field.doc

Definition at line 179 of file config.py.

◆ dtype

lsst.pex.config.config.Field.dtype

Definition at line 178 of file config.py.

◆ optional

lsst.pex.config.config.Field.optional

Definition at line 183 of file config.py.

◆ source

lsst.pex.config.config.Field.source

Definition at line 184 of file config.py.

◆ supportedTypes

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

Definition at line 153 of file config.py.


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