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.listField.List Class Reference
Inheritance diagram for lsst.pex.config.listField.List:
lsst.pex.config.listField.ListField

Public Member Functions

 __init__ (self, Config config, ListField field, Sequence[FieldTypeVar] value, list[StackFrame]|None at, str label, bool setHistory=True)
 
 validateItem (self, i, x)
 
 list (self)
 
 __contains__ (self, x)
 
 __len__ (self)
 
None __setitem__ (self, int i, FieldTypeVar x, Any at=None, str label="setitem", bool setHistory=True)
 
None __setitem__ (self, slice i, Iterable[FieldTypeVar] x, Any at=None, str label="setitem", bool setHistory=True)
 
 __setitem__ (self, i, x, at=None, label="setitem", setHistory=True)
 
FieldTypeVar __getitem__ (self, int i)
 
MutableSequence[FieldTypeVar] __getitem__ (self, slice i)
 
 __getitem__ (self, i)
 
 __delitem__ (self, i, at=None, label="delitem", setHistory=True)
 
 __iter__ (self)
 
 insert (self, i, x, at=None, label="insert", setHistory=True)
 
 __repr__ (self)
 
 __str__ (self)
 
 __eq__ (self, other)
 
 __ne__ (self, other)
 
 __setattr__ (self, attr, value, at=None, label="assignment")
 
 __reduce__ (self)
 

Protected Member Functions

Config _config (self)
 
List _copy (self, Config config)
 

Protected Attributes

 _field = field
 
 _config_ = weakref.ref(config)
 
Config _history = self._config._history.setdefault(self._field.name, [])
 
list _list = []
 
 _config
 

Properties

 history = property(lambda x: x._history)
 

Detailed Description

List collection used internally by `ListField`.

Parameters
----------
config : `lsst.pex.config.Config`
    Config instance that contains the ``field``.
field : `ListField`
    Instance of the `ListField` using this ``List``.
value : sequence
    Sequence of values that are inserted into this ``List``.
at : `list` of `~lsst.pex.config.callStack.StackFrame`
    The call stack (created by `lsst.pex.config.callStack.getCallStack`).
label : `str`
    Event label for the history.
setHistory : `bool`, optional
    Enable setting the field's history, using the value of the ``at``
    parameter. Default is `True`.

Raises
------
FieldValidationError
    Raised if an item in the ``value`` parameter does not have the
    appropriate type for this field or does not pass the
    `ListField.itemCheck` method of the ``field`` parameter.

Definition at line 51 of file listField.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.pex.config.listField.List.__init__ ( self,
Config config,
ListField field,
Sequence[FieldTypeVar] value,
list[StackFrame] | None at,
str label,
bool setHistory = True )

Definition at line 78 of file listField.py.

86 ):
87 self._field = field
88 self._config_ = weakref.ref(config)
89 self._history = self._config._history.setdefault(self._field.name, [])
90 self._list = []
91 self.__doc__ = field.doc
92 if value is not None:
93 try:
94 for i, x in enumerate(value):
95 self.insert(i, x, setHistory=False)
96 except TypeError as e:
97 msg = f"Value {value} is of incorrect type {_typeStr(value)}. Sequence type expected"
98 raise FieldValidationError(self._field, config, msg) from e
99 if setHistory:
100 self.history.append((list(self._list), at, label))
101

Member Function Documentation

◆ __contains__()

lsst.pex.config.listField.List.__contains__ ( self,
x )

Definition at line 149 of file listField.py.

149 def __contains__(self, x):
150 return x in self._list
151

◆ __delitem__()

lsst.pex.config.listField.List.__delitem__ ( self,
i,
at = None,
label = "delitem",
setHistory = True )

Definition at line 199 of file listField.py.

199 def __delitem__(self, i, at=None, label="delitem", setHistory=True):
200 if self._config._frozen:
201 raise FieldValidationError(self._field, self._config, "Cannot modify a frozen Config")
202 del self._list[i]
203 if setHistory:
204 if at is None:
205 at = getCallStack()
206 self.history.append((list(self._list), at, label))
207

◆ __eq__()

lsst.pex.config.listField.List.__eq__ ( self,
other )

Definition at line 240 of file listField.py.

240 def __eq__(self, other):
241 if other is None:
242 return False
243 try:
244 if len(self) != len(other):
245 return False
246
247 for i, j in zip(self, other, strict=True):
248 if i != j:
249 return False
250 return True
251 except AttributeError:
252 # other is not a sequence type
253 return False
254

◆ __getitem__() [1/3]

lsst.pex.config.listField.List.__getitem__ ( self,
i )

Definition at line 196 of file listField.py.

196 def __getitem__(self, i):
197 return self._list[i]
198

◆ __getitem__() [2/3]

FieldTypeVar lsst.pex.config.listField.List.__getitem__ ( self,
int i )

Definition at line 191 of file listField.py.

191 def __getitem__(self, i: int) -> FieldTypeVar: ...
192

◆ __getitem__() [3/3]

MutableSequence[FieldTypeVar] lsst.pex.config.listField.List.__getitem__ ( self,
slice i )

Definition at line 194 of file listField.py.

194 def __getitem__(self, i: slice) -> MutableSequence[FieldTypeVar]: ...
195

◆ __iter__()

lsst.pex.config.listField.List.__iter__ ( self)

Definition at line 208 of file listField.py.

208 def __iter__(self):
209 return iter(self._list)
210

◆ __len__()

lsst.pex.config.listField.List.__len__ ( self)

Definition at line 152 of file listField.py.

152 def __len__(self):
153 return len(self._list)
154

◆ __ne__()

lsst.pex.config.listField.List.__ne__ ( self,
other )

Definition at line 255 of file listField.py.

255 def __ne__(self, other):
256 return not self.__eq__(other)
257

◆ __reduce__()

lsst.pex.config.listField.List.__reduce__ ( self)

Definition at line 270 of file listField.py.

270 def __reduce__(self):
271 raise UnexpectedProxyUsageError(
272 f"Proxy container for config field {self._field.name} cannot "
273 "be pickled; it should be converted to a built-in container before "
274 "being assigned to other objects or variables."
275 )
276
277

◆ __repr__()

lsst.pex.config.listField.List.__repr__ ( self)

Definition at line 234 of file listField.py.

234 def __repr__(self):
235 return repr(self._list)
236

◆ __setattr__()

lsst.pex.config.listField.List.__setattr__ ( self,
attr,
value,
at = None,
label = "assignment" )

Definition at line 258 of file listField.py.

258 def __setattr__(self, attr, value, at=None, label="assignment"):
259 if hasattr(getattr(self.__class__, attr, None), "__set__"):
260 # This allows properties to work.
261 object.__setattr__(self, attr, value)
262 elif attr in self.__dict__ or attr in ["_field", "_config_", "_history", "_list", "__doc__"]:
263 # This allows specific private attributes to work.
264 object.__setattr__(self, attr, value)
265 else:
266 # We throw everything else.
267 msg = f"{_typeStr(self._field)} has no attribute {attr}"
268 raise FieldValidationError(self._field, self._config, msg)
269

◆ __setitem__() [1/3]

lsst.pex.config.listField.List.__setitem__ ( self,
i,
x,
at = None,
label = "setitem",
setHistory = True )

Definition at line 170 of file listField.py.

170 def __setitem__(self, i, x, at=None, label="setitem", setHistory=True):
171 if self._config._frozen:
172 raise FieldValidationError(self._field, self._config, "Cannot modify a frozen Config")
173 if isinstance(i, slice):
174 k, stop, step = i.indices(len(self))
175 for j, xj in enumerate(x):
176 xj = _autocast(xj, self._field.itemtype)
177 self.validateItem(k, xj)
178 x[j] = xj
179 k += step
180 else:
181 x = _autocast(x, self._field.itemtype)
182 self.validateItem(i, x)
183
184 self._list[i] = x
185 if setHistory:
186 if at is None:
187 at = getCallStack()
188 self.history.append((list(self._list), at, label))
189

◆ __setitem__() [2/3]

None lsst.pex.config.listField.List.__setitem__ ( self,
int i,
FieldTypeVar x,
Any at = None,
str label = "setitem",
bool setHistory = True )

Definition at line 156 of file listField.py.

158 ) -> None: ...
159

◆ __setitem__() [3/3]

None lsst.pex.config.listField.List.__setitem__ ( self,
slice i,
Iterable[FieldTypeVar] x,
Any at = None,
str label = "setitem",
bool setHistory = True )

Definition at line 161 of file listField.py.

168 ) -> None: ...
169

◆ __str__()

lsst.pex.config.listField.List.__str__ ( self)

Definition at line 237 of file listField.py.

237 def __str__(self):
238 return str(self._list)
239

◆ _config()

Config lsst.pex.config.listField.List._config ( self)
protected

Definition at line 103 of file listField.py.

103 def _config(self) -> Config:
104 # Config Fields should never outlive their config class instance
105 # assert that as such here
106 value = self._config_()
107 assert value is not None
108 return value
109

◆ _copy()

List lsst.pex.config.listField.List._copy ( self,
Config config )
protected

Definition at line 146 of file listField.py.

146 def _copy(self, config: Config) -> List:
147 return type(self)(config, self._field, self._list.copy(), at=None, label="copy", setHistory=False)
148

◆ insert()

lsst.pex.config.listField.List.insert ( self,
i,
x,
at = None,
label = "insert",
setHistory = True )
Insert an item into the list at the given index.

Parameters
----------
i : `int`
    Index where the item is inserted.
x : object
    Item that is inserted.
at : `list` of `~lsst.pex.config.callStack.StackFrame` or `None`,\
        optional
    The call stack (created by
    `lsst.pex.config.callStack.getCallStack`).
label : `str`, optional
    Event label for the history.
setHistory : `bool`, optional
    Enable setting the field's history, using the value of the ``at``
    parameter. Default is `True`.

Definition at line 211 of file listField.py.

211 def insert(self, i, x, at=None, label="insert", setHistory=True):
212 """Insert an item into the list at the given index.
213
214 Parameters
215 ----------
216 i : `int`
217 Index where the item is inserted.
218 x : object
219 Item that is inserted.
220 at : `list` of `~lsst.pex.config.callStack.StackFrame` or `None`,\
221 optional
222 The call stack (created by
223 `lsst.pex.config.callStack.getCallStack`).
224 label : `str`, optional
225 Event label for the history.
226 setHistory : `bool`, optional
227 Enable setting the field's history, using the value of the ``at``
228 parameter. Default is `True`.
229 """
230 if at is None:
231 at = getCallStack()
232 self.__setitem__(slice(i, i), [x], at=at, label=label, setHistory=setHistory)
233

◆ list()

lsst.pex.config.listField.List.list ( self)
Sequence of items contained by the `List` (`list`).

Definition at line 138 of file listField.py.

138 def list(self):
139 """Sequence of items contained by the `List` (`list`)."""
140 return self._list
141

◆ validateItem()

lsst.pex.config.listField.List.validateItem ( self,
i,
x )
Validate an item to determine if it can be included in the list.

Parameters
----------
i : `int`
    Index of the item in the `list`.
x : object
    Item in the `list`.

Raises
------
FieldValidationError
    Raised if an item in the ``value`` parameter does not have the
    appropriate type for this field or does not pass the field's
    `ListField.itemCheck` method.

Definition at line 110 of file listField.py.

110 def validateItem(self, i, x):
111 """Validate an item to determine if it can be included in the list.
112
113 Parameters
114 ----------
115 i : `int`
116 Index of the item in the `list`.
117 x : object
118 Item in the `list`.
119
120 Raises
121 ------
122 FieldValidationError
123 Raised if an item in the ``value`` parameter does not have the
124 appropriate type for this field or does not pass the field's
125 `ListField.itemCheck` method.
126 """
127 if not isinstance(x, self._field.itemtype) and x is not None:
128 msg = (
129 f"Item at position {i} with value {x} is of incorrect type {_typeStr(x)}. "
130 f"Expected {_typeStr(self._field.itemtype)}"
131 )
132 raise FieldValidationError(self._field, self._config, msg)
133
134 if self._field.itemCheck is not None and not self._field.itemCheck(x):
135 msg = f"Item at position {i} is not a valid value: {x}"
136 raise FieldValidationError(self._field, self._config, msg)
137

Member Data Documentation

◆ _config

lsst.pex.config.listField.List._config
protected

Definition at line 132 of file listField.py.

◆ _config_

lsst.pex.config.listField.List._config_ = weakref.ref(config)
protected

Definition at line 88 of file listField.py.

◆ _field

lsst.pex.config.listField.List._field = field
protected

Definition at line 87 of file listField.py.

◆ _history

Config lsst.pex.config.listField.List._history = self._config._history.setdefault(self._field.name, [])
protected

Definition at line 89 of file listField.py.

◆ _list

lsst.pex.config.listField.List._list = []
protected

Definition at line 90 of file listField.py.

Property Documentation

◆ history

lsst.pex.config.listField.List.history = property(lambda x: x._history)
static

Definition at line 142 of file listField.py.


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