LSST Applications 27.0.0,g0265f82a02+469cd937ee,g02d81e74bb+21ad69e7e1,g1470d8bcf6+cbe83ee85a,g2079a07aa2+e67c6346a6,g212a7c68fe+04a9158687,g2305ad1205+94392ce272,g295015adf3+81dd352a9d,g2bbee38e9b+469cd937ee,g337abbeb29+469cd937ee,g3939d97d7f+72a9f7b576,g487adcacf7+71499e7cba,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+df404f777f,g5a732f18d5+be83d3ecdb,g64a986408d+21ad69e7e1,g858d7b2824+21ad69e7e1,g8a8a8dda67+a6fc98d2e7,g99cad8db69+f62e5b0af5,g9ddcbc5298+d4bad12328,ga1e77700b3+9c366c4306,ga8c6da7877+71e4819109,gb0e22166c9+25ba2f69a1,gb6a65358fc+469cd937ee,gbb8dafda3b+69d3c0e320,gc07e1c2157+a98bf949bb,gc120e1dc64+615ec43309,gc28159a63d+469cd937ee,gcf0d15dbbd+72a9f7b576,gdaeeff99f8+a38ce5ea23,ge6526c86ff+3a7c1ac5f1,ge79ae78c31+469cd937ee,gee10cc3b42+a6fc98d2e7,gf1cff7945b+21ad69e7e1,gfbcc870c63+9a11dc8c8f
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 188 of file listField.py.

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

◆ __eq__()

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

Definition at line 229 of file listField.py.

229 def __eq__(self, other):
230 try:
231 if len(self) != len(other):
232 return False
233
234 for i, j in zip(self, other):
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 185 of file listField.py.

185 def __getitem__(self, i):
186 return self._list[i]
187

◆ __getitem__() [2/3]

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

Definition at line 180 of file listField.py.

180 def __getitem__(self, i: int) -> FieldTypeVar: ...
181

◆ __getitem__() [3/3]

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

Definition at line 183 of file listField.py.

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

◆ __iter__()

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

Definition at line 197 of file listField.py.

197 def __iter__(self):
198 return iter(self._list)
199

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

223 def __repr__(self):
224 return repr(self._list)
225

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

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

◆ __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

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

157 ) -> None: ...
158

◆ __str__()

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

Definition at line 226 of file listField.py.

226 def __str__(self):
227 return str(self._list)
228

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

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

◆ 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: