LSST Applications g0265f82a02+0e5473021a,g02d81e74bb+f5613e8b4f,g1470d8bcf6+190ad2ba91,g14a832a312+311607e4ab,g2079a07aa2+86d27d4dc4,g2305ad1205+a8e3196225,g295015adf3+b67ee847e5,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g3ddfee87b4+a761f810f3,g487adcacf7+17c8fdbcbd,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+65b5bd823e,g5a732f18d5+53520f316c,g64a986408d+f5613e8b4f,g6c1bc301e9+51106c2951,g858d7b2824+f5613e8b4f,g8a8a8dda67+585e252eca,g99cad8db69+6729933424,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+ef4e3a5875,gb0e22166c9+60f28cb32d,gb6a65358fc+0e5473021a,gba4ed39666+c2a2e4ac27,gbb8dafda3b+e9bba80f27,gc120e1dc64+eee469a5e5,gc28159a63d+0e5473021a,gcf0d15dbbd+a761f810f3,gdaeeff99f8+f9a426f77a,ge6526c86ff+d4c1d4bfef,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gf1cff7945b+f5613e8b4f,w.2024.16
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Properties | List of all members
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
 
 _config_
 
 _history
 
 _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 )

Reimplemented in lsst.pex.config.listField.ListField.

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:
87 msg = f"Value {value} is of incorrect type {_typeStr(value)}. Sequence type expected"
88 raise FieldValidationError(self._field, config, msg)
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 138 of file listField.py.

138 def __contains__(self, x):
139 return x in self._list
140

◆ __delitem__()

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

Definition at line 192 of file listField.py.

192 def __delitem__(self, i, at=None, label="delitem", setHistory=True):
193 if self._config._frozen:
194 raise FieldValidationError(self._field, self._config, "Cannot modify a frozen Config")
195 del self._list[i]
196 if setHistory:
197 if at is None:
198 at = getCallStack()
199 self.history.append((list(self._list), at, label))
200

◆ __eq__()

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

Definition at line 233 of file listField.py.

233 def __eq__(self, other):
234 try:
235 if len(self) != len(other):
236 return False
237
238 for i, j in zip(self, other):
239 if i != j:
240 return False
241 return True
242 except AttributeError:
243 # other is not a sequence type
244 return False
245

◆ __getitem__() [1/3]

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

Definition at line 189 of file listField.py.

189 def __getitem__(self, i):
190 return self._list[i]
191

◆ __getitem__() [2/3]

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

Definition at line 182 of file listField.py.

182 def __getitem__(self, i: int) -> FieldTypeVar:
183 ...
184

◆ __getitem__() [3/3]

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

Definition at line 186 of file listField.py.

186 def __getitem__(self, i: slice) -> MutableSequence[FieldTypeVar]:
187 ...
188

◆ __iter__()

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

Definition at line 201 of file listField.py.

201 def __iter__(self):
202 return iter(self._list)
203

◆ __len__()

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

Definition at line 141 of file listField.py.

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

◆ __ne__()

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

Definition at line 246 of file listField.py.

246 def __ne__(self, other):
247 return not self.__eq__(other)
248

◆ __reduce__()

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

Definition at line 261 of file listField.py.

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

◆ __repr__()

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

Definition at line 227 of file listField.py.

227 def __repr__(self):
228 return repr(self._list)
229

◆ __setattr__()

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

Definition at line 249 of file listField.py.

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

◆ __setitem__() [1/3]

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

Definition at line 161 of file listField.py.

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

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

147 ) -> None:
148 ...
149

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

158 ) -> None:
159 ...
160

◆ __str__()

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

Definition at line 230 of file listField.py.

230 def __str__(self):
231 return str(self._list)
232

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

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

◆ list()

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

Definition at line 130 of file listField.py.

130 def list(self):
131 """Sequence of items contained by the `List` (`list`)."""
132 return self._list
133
daf::base::PropertyList * list
Definition fits.cc:932

◆ 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 = "Item at position %d with value %s is of incorrect type %s. Expected %s" % (
119 i,
120 x,
121 _typeStr(x),
122 _typeStr(self._field.itemtype),
123 )
124 raise FieldValidationError(self._field, self._config, msg)
125
126 if self._field.itemCheck is not None and not self._field.itemCheck(x):
127 msg = "Item at position %d is not a valid value: %s" % (i, x)
128 raise FieldValidationError(self._field, self._config, msg)
129

Member Data Documentation

◆ _config

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

Definition at line 124 of file listField.py.

◆ _config_

lsst.pex.config.listField.List._config_
protected

Definition at line 78 of file listField.py.

◆ _field

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

Definition at line 77 of file listField.py.

◆ _history

lsst.pex.config.listField.List._history
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 134 of file listField.py.


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