LSST Applications g00274db5b6+edbf708997,g00d0e8bbd7+edbf708997,g199a45376c+5137f08352,g1fd858c14a+1d4b6db739,g262e1987ae+f4d9505c4f,g29ae962dfc+7156fb1a53,g2cef7863aa+73c82f25e4,g35bb328faa+edbf708997,g3e17d7035e+5b3adc59f5,g3fd5ace14f+852fa6fbcb,g47891489e3+6dc8069a4c,g53246c7159+edbf708997,g64539dfbff+9f17e571f4,g67b6fd64d1+6dc8069a4c,g74acd417e5+ae494d68d9,g786e29fd12+af89c03590,g7ae74a0b1c+a25e60b391,g7aefaa3e3d+536efcc10a,g7cc15d900a+d121454f8d,g87389fa792+a4172ec7da,g89139ef638+6dc8069a4c,g8d7436a09f+28c28d8d6d,g8ea07a8fe4+db21c37724,g92c671f44c+9f17e571f4,g98df359435+b2e6376b13,g99af87f6a8+b0f4ad7b8d,gac66b60396+966efe6077,gb88ae4c679+7dec8f19df,gbaa8f7a6c5+38b34f4976,gbf99507273+edbf708997,gc24b5d6ed1+9f17e571f4,gca7fc764a6+6dc8069a4c,gcc769fe2a4+97d0256649,gd7ef33dd92+6dc8069a4c,gdab6d2f7ff+ae494d68d9,gdbb4c4dda9+9f17e571f4,ge410e46f29+6dc8069a4c,geaed405ab2+e194be0d2b,w.2025.47
LSST Data Management Base Package
Loading...
Searching...
No Matches
lsst.pex.config.configChoiceField.SelectionSet Class Reference
Inheritance diagram for lsst.pex.config.configChoiceField.SelectionSet:

Public Member Functions

 __init__ (self, ConfigInstanceDict dict_, Any value, at=None, str label="assignment", bool setHistory=True)
 
 add (self, value, at=None)
 
 discard (self, value, at=None)
 
 __len__ (self)
 
 __iter__ (self)
 
 __contains__ (self, value)
 
 __repr__ (self)
 
 __str__ (self)
 
 __reduce__ (self)
 

Protected Attributes

 _dict = dict_
 
 _field = self._dict._field
 
 _history = self._dict._config._history.setdefault(self._field.name, [])
 
 _set = set(value)
 
 _config
 

Detailed Description

A mutable set class that tracks the selection of multi-select
`~lsst.pex.config.ConfigChoiceField` objects.

Parameters
----------
dict_ : `ConfigInstanceDict`
    The dictionary of instantiated configs.
value : `~typing.Any`
    The selected key.
at : `list` of `~lsst.pex.config.callStack.StackFrame` or `None`, optional
    The call stack when the selection was made.
label : `str`, optional
    Label for history tracking.
setHistory : `bool`, optional
    Add this even to the history, if `True`.

Notes
-----
This class allows a user of a multi-select
`~lsst.pex.config.ConfigChoiceField` to add or discard items from the set
of active configs. Each change to the selection is tracked in the field's
history.

Definition at line 40 of file configChoiceField.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.pex.config.configChoiceField.SelectionSet.__init__ ( self,
ConfigInstanceDict dict_,
Any value,
at = None,
str label = "assignment",
bool setHistory = True )

Definition at line 65 of file configChoiceField.py.

72 ):
73 if at is None:
74 at = getCallStack()
75 self._dict = dict_
76 self._field = self._dict._field
77 self._history = self._dict._config._history.setdefault(self._field.name, [])
78 if value is not None:
79 try:
80 for v in value:
81 if v not in self._dict:
82 # invoke __getitem__ to ensure it's present
83 self._dict.__getitem__(v, at=at)
84 except TypeError as e:
85 msg = f"Value {value} is of incorrect type {_typeStr(value)}. Sequence type expected"
86 raise FieldValidationError(self._field, self._dict._config, msg) from e
87 self._set = set(value)
88 else:
89 self._set = set()
90
91 if setHistory:
92 self._history.append((f"Set selection to {self}", at, label))
93

Member Function Documentation

◆ __contains__()

lsst.pex.config.configChoiceField.SelectionSet.__contains__ ( self,
value )

Definition at line 147 of file configChoiceField.py.

147 def __contains__(self, value):
148 return value in self._set
149

◆ __iter__()

lsst.pex.config.configChoiceField.SelectionSet.__iter__ ( self)

Definition at line 144 of file configChoiceField.py.

144 def __iter__(self):
145 return iter(self._set)
146

◆ __len__()

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

Definition at line 141 of file configChoiceField.py.

141 def __len__(self):
142 return len(self._set)
143

◆ __reduce__()

lsst.pex.config.configChoiceField.SelectionSet.__reduce__ ( self)

Definition at line 156 of file configChoiceField.py.

156 def __reduce__(self):
157 raise UnexpectedProxyUsageError(
158 f"Proxy container for config field {self._field.name} cannot "
159 "be pickled; it should be converted to a built-in container before "
160 "being assigned to other objects or variables."
161 )
162
163

◆ __repr__()

lsst.pex.config.configChoiceField.SelectionSet.__repr__ ( self)

Definition at line 150 of file configChoiceField.py.

150 def __repr__(self):
151 return repr(list(self._set))
152

◆ __str__()

lsst.pex.config.configChoiceField.SelectionSet.__str__ ( self)

Definition at line 153 of file configChoiceField.py.

153 def __str__(self):
154 return str(list(self._set))
155

◆ add()

lsst.pex.config.configChoiceField.SelectionSet.add ( self,
value,
at = None )
Add a value to the selected set.

Parameters
----------
value : `~typing.Any`
    The selected key.
at : `list` of `~lsst.pex.config.callStack.StackFrame` or `None`,\
        optional
    Stack frames for history recording.

Definition at line 94 of file configChoiceField.py.

94 def add(self, value, at=None):
95 """Add a value to the selected set.
96
97 Parameters
98 ----------
99 value : `~typing.Any`
100 The selected key.
101 at : `list` of `~lsst.pex.config.callStack.StackFrame` or `None`,\
102 optional
103 Stack frames for history recording.
104 """
105 if self._dict._config._frozen:
106 raise FieldValidationError(self._field, self._config, "Cannot modify a frozen Config")
107
108 if at is None:
109 at = getCallStack()
110
111 if value not in self._dict:
112 # invoke __getitem__ to make sure it's present
113 self._dict.__getitem__(value, at=at)
114
115 self._history.append((f"added {value} to selection", at, "selection"))
116 self._set.add(value)
117

◆ discard()

lsst.pex.config.configChoiceField.SelectionSet.discard ( self,
value,
at = None )
Discard a value from the selected set.

Parameters
----------
value : `~typing.Any`
    The selected key.
at : `list` of `~lsst.pex.config.callStack.StackFrame` or `None`,\
        optional
    Stack frames for history recording.

Definition at line 118 of file configChoiceField.py.

118 def discard(self, value, at=None):
119 """Discard a value from the selected set.
120
121 Parameters
122 ----------
123 value : `~typing.Any`
124 The selected key.
125 at : `list` of `~lsst.pex.config.callStack.StackFrame` or `None`,\
126 optional
127 Stack frames for history recording.
128 """
129 if self._dict._config._frozen:
130 raise FieldValidationError(self._field, self._dict._config, "Cannot modify a frozen Config")
131
132 if value not in self._dict:
133 return
134
135 if at is None:
136 at = getCallStack()
137
138 self._history.append((f"removed {value} from selection", at, "selection"))
139 self._set.discard(value)
140

Member Data Documentation

◆ _config

lsst.pex.config.configChoiceField.SelectionSet._config
protected

Definition at line 106 of file configChoiceField.py.

◆ _dict

lsst.pex.config.configChoiceField.SelectionSet._dict = dict_
protected

Definition at line 75 of file configChoiceField.py.

◆ _field

lsst.pex.config.configChoiceField.SelectionSet._field = self._dict._field
protected

Definition at line 76 of file configChoiceField.py.

◆ _history

lsst.pex.config.configChoiceField.SelectionSet._history = self._dict._config._history.setdefault(self._field.name, [])
protected

Definition at line 77 of file configChoiceField.py.

◆ _set

lsst.pex.config.configChoiceField.SelectionSet._set = set(value)
protected

Definition at line 87 of file configChoiceField.py.


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