LSST Applications g04e9c324dd+8c5ae1fdc5,g0644efc3f0+366663dc37,g123d84c11c+8c5ae1fdc5,g1ec0fe41b4+6ec6b74de1,g1fd858c14a+1be88e80db,g3533f9d6cb+366663dc37,g35bb328faa+8c5ae1fdc5,g35ef7ab7cf+285dd5b202,g53246c7159+8c5ae1fdc5,g60b5630c4e+366663dc37,g663da51e9b+41529343ca,g6735e52a0d+29de3d959a,g67b6fd64d1+57193d00fb,g7605de067c+8f72e4d2dc,g78460c75b0+7e33a9eb6d,g786e29fd12+668abc6043,g844c57033c+03ddc13274,g8852436030+e345a59dd4,g89139ef638+57193d00fb,g989de1cb63+57193d00fb,g9a0bdda227+852181cf57,g9f33ca652e+a2d35689ce,ga1e959baac+5fbc491aed,ga2f891cd6c+366663dc37,gabe3b4be73+8856018cbb,gabf8522325+cc757f8247,gac2eed3f23+57193d00fb,gb1101e3267+f6b489998a,gb89ab40317+57193d00fb,gcf25f946ba+e345a59dd4,gd107969129+227687db21,gd6cbbdb0b4+8e46defd2a,gde0f65d7ad+2dad650f79,ge278dab8ac+2322f1d6ea,ge410e46f29+57193d00fb,gf30d85a44d+8e3077faf9,gf5e32f922b+8c5ae1fdc5,gff02db199a+5c78c1866e,w.2025.28
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, field, value, at, label, 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)
 

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 49 of file listField.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.pex.config.listField.List.__init__ ( self,
config,
field,
value,
at,
label,
setHistory = True )

Definition at line 76 of file listField.py.

76 def __init__(self, config, field, value, at, label, setHistory=True):
77 self._field = field
78 self._config_ = weakref.ref(config)
79 self._history = self._config._history.setdefault(self._field.name, [])
80 self._list = []
81 self.__doc__ = field.doc
82 if value is not None:
83 try:
84 for i, x in enumerate(value):
85 self.insert(i, x, setHistory=False)
86 except TypeError as e:
87 msg = f"Value {value} is of incorrect type {_typeStr(value)}. Sequence type expected"
88 raise FieldValidationError(self._field, config, msg) from e
89 if setHistory:
90 self.history.append((list(self._list), at, label))
91

Member Function Documentation

◆ __contains__()

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

Definition at line 136 of file listField.py.

136 def __contains__(self, x):
137 return x in self._list
138

◆ __delitem__()

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

Definition at line 186 of file listField.py.

186 def __delitem__(self, i, at=None, label="delitem", setHistory=True):
187 if self._config._frozen:
188 raise FieldValidationError(self._field, self._config, "Cannot modify a frozen Config")
189 del self._list[i]
190 if setHistory:
191 if at is None:
192 at = getCallStack()
193 self.history.append((list(self._list), at, label))
194

◆ __eq__()

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

Definition at line 227 of file listField.py.

227 def __eq__(self, other):
228 if other is None:
229 return False
230 try:
231 if len(self) != len(other):
232 return False
233
234 for i, j in zip(self, other, strict=True):
235 if i != j:
236 return False
237 return True
238 except AttributeError:
239 # other is not a sequence type
240 return False
241

◆ __getitem__() [1/3]

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

Definition at line 183 of file listField.py.

183 def __getitem__(self, i):
184 return self._list[i]
185

◆ __getitem__() [2/3]

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

Definition at line 178 of file listField.py.

178 def __getitem__(self, i: int) -> FieldTypeVar: ...
179

◆ __getitem__() [3/3]

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

Definition at line 181 of file listField.py.

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

◆ __iter__()

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

Definition at line 195 of file listField.py.

195 def __iter__(self):
196 return iter(self._list)
197

◆ __len__()

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

Definition at line 139 of file listField.py.

139 def __len__(self):
140 return len(self._list)
141

◆ __ne__()

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

Definition at line 242 of file listField.py.

242 def __ne__(self, other):
243 return not self.__eq__(other)
244

◆ __reduce__()

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

Definition at line 257 of file listField.py.

257 def __reduce__(self):
258 raise UnexpectedProxyUsageError(
259 f"Proxy container for config field {self._field.name} cannot "
260 "be pickled; it should be converted to a built-in container before "
261 "being assigned to other objects or variables."
262 )
263
264

◆ __repr__()

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

Definition at line 221 of file listField.py.

221 def __repr__(self):
222 return repr(self._list)
223

◆ __setattr__()

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

Definition at line 245 of file listField.py.

245 def __setattr__(self, attr, value, at=None, label="assignment"):
246 if hasattr(getattr(self.__class__, attr, None), "__set__"):
247 # This allows properties to work.
248 object.__setattr__(self, attr, value)
249 elif attr in self.__dict__ or attr in ["_field", "_config_", "_history", "_list", "__doc__"]:
250 # This allows specific private attributes to work.
251 object.__setattr__(self, attr, value)
252 else:
253 # We throw everything else.
254 msg = f"{_typeStr(self._field)} has no attribute {attr}"
255 raise FieldValidationError(self._field, self._config, msg)
256

◆ __setitem__() [1/3]

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

Definition at line 157 of file listField.py.

157 def __setitem__(self, i, x, at=None, label="setitem", setHistory=True):
158 if self._config._frozen:
159 raise FieldValidationError(self._field, self._config, "Cannot modify a frozen Config")
160 if isinstance(i, slice):
161 k, stop, step = i.indices(len(self))
162 for j, xj in enumerate(x):
163 xj = _autocast(xj, self._field.itemtype)
164 self.validateItem(k, xj)
165 x[j] = xj
166 k += step
167 else:
168 x = _autocast(x, self._field.itemtype)
169 self.validateItem(i, x)
170
171 self._list[i] = x
172 if setHistory:
173 if at is None:
174 at = getCallStack()
175 self.history.append((list(self._list), at, label))
176

◆ __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 143 of file listField.py.

145 ) -> None: ...
146

◆ __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 148 of file listField.py.

155 ) -> None: ...
156

◆ __str__()

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

Definition at line 224 of file listField.py.

224 def __str__(self):
225 return str(self._list)
226

◆ _config()

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

Definition at line 93 of file listField.py.

93 def _config(self) -> Config:
94 # Config Fields should never outlive their config class instance
95 # assert that as such here
96 value = self._config_()
97 assert value is not None
98 return value
99

◆ 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 198 of file listField.py.

198 def insert(self, i, x, at=None, label="insert", setHistory=True):
199 """Insert an item into the list at the given index.
200
201 Parameters
202 ----------
203 i : `int`
204 Index where the item is inserted.
205 x : object
206 Item that is inserted.
207 at : `list` of `~lsst.pex.config.callStack.StackFrame` or `None`,\
208 optional
209 The call stack (created by
210 `lsst.pex.config.callStack.getCallStack`).
211 label : `str`, optional
212 Event label for the history.
213 setHistory : `bool`, optional
214 Enable setting the field's history, using the value of the ``at``
215 parameter. Default is `True`.
216 """
217 if at is None:
218 at = getCallStack()
219 self.__setitem__(slice(i, i), [x], at=at, label=label, setHistory=setHistory)
220

◆ list()

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

Definition at line 128 of file listField.py.

128 def list(self):
129 """Sequence of items contained by the `List` (`list`)."""
130 return self._list
131

◆ 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 100 of file listField.py.

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

Member Data Documentation

◆ _config

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

Definition at line 122 of file listField.py.

◆ _config_

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

Definition at line 78 of file listField.py.

◆ _field

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

Definition at line 77 of file listField.py.

◆ _history

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

Definition at line 79 of file listField.py.

◆ _list

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

Definition at line 80 of file listField.py.

Property Documentation

◆ history

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

Definition at line 132 of file listField.py.


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