LSST Applications 29.1.0,g0fba68d861+6b120c4394,g123d84c11c+8c5ae1fdc5,g1ec0fe41b4+191117f6ec,g1fd858c14a+c8450ae71a,g3533f9d6cb+a04f9ee0ab,g35bb328faa+8c5ae1fdc5,g3f0dcc2b1b+7df08700bd,g4178042926+b4254969db,g44ba364a48+04455b336b,g53246c7159+8c5ae1fdc5,g60b5630c4e+a04f9ee0ab,g663da51e9b+b05e6e1875,g67b6fd64d1+250bf6acd3,g78460c75b0+7e33a9eb6d,g786e29fd12+668abc6043,g8352419a5c+8c5ae1fdc5,g87e3079a85+d3fa38de54,g8852436030+cd899e2626,g89139ef638+250bf6acd3,g93a033419f+31ead11197,g989de1cb63+250bf6acd3,g9f33ca652e+f6053ecf14,ga1e959baac+5fbc491aed,ga2f891cd6c+a04f9ee0ab,gabe3b4be73+8856018cbb,gabf8522325+1f7e6d67b9,gac2eed3f23+250bf6acd3,gb1101e3267+0c331e9486,gb89ab40317+250bf6acd3,gcf25f946ba+cd899e2626,gd107969129+8964d67276,gd6cbbdb0b4+6bbecc8878,gde0f65d7ad+d65f9e019a,ge278dab8ac+eb3bbeb12f,ge410e46f29+250bf6acd3,gf5e32f922b+8c5ae1fdc5,gff02db199a+747430a128,gffe7e49bb4+a04f9ee0ab
LSST Data Management Base Package
Loading...
Searching...
No Matches
lsst.pex.config.dictField.Dict Class Reference
Inheritance diagram for lsst.pex.config.dictField.Dict:
lsst.pex.config.configDictField.ConfigDict lsst.pex.config.dictField.DictField lsst.pex.config.configDictField.ConfigDictField

Public Member Functions

 __init__ (self, config, field, value, at, label, setHistory=True)
 
ItemTypeVar __getitem__ (self, KeyTypeVar k)
 
int __len__ (self)
 
Iterator[KeyTypeVar__iter__ (self)
 
bool __contains__ (self, Any k)
 
None __setitem__ (self, KeyTypeVar k, ItemTypeVar x, Any at=None, str label="setitem", bool setHistory=True)
 
None __delitem__ (self, KeyTypeVar k, Any at=None, str label="delitem", bool setHistory=True)
 
 __repr__ (self)
 
 __str__ (self)
 
 __setattr__ (self, attr, value, at=None, label="assignment")
 
 __reduce__ (self)
 

Protected Member Functions

Config _config (self)
 

Protected Attributes

 _field = field
 
 _config_ = weakref.ref(config)
 
dict _dict = {}
 
Config _history = self._config._history.setdefault(self._field.name, [])
 
 _config
 

Properties

 history = property(lambda x: x._history)
 

Detailed Description

An internal mapping container.

This class emulates a `dict`, but adds validation and provenance.

Parameters
----------
config : `~lsst.pex.config.Config`
    Config to proxy.
field : `~lsst.pex.config.DictField`
    Field to use.
value : `~typing.Any`
    Value to store.
at : `list` of `~lsst.pex.config.callStack.StackFrame`
    Stack frame for history recording. Will be calculated if `None`.
label : `str`, optional
    Label to use for history recording.
setHistory : `bool`, optional
    Whether to append to the history record.

Definition at line 53 of file dictField.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 74 of file dictField.py.

74 def __init__(self, config, field, value, at, label, setHistory=True):
75 self._field = field
76 self._config_ = weakref.ref(config)
77 self._dict = {}
78 self._history = self._config._history.setdefault(self._field.name, [])
79 self.__doc__ = field.doc
80 if value is not None:
81 try:
82 for k in value:
83 # do not set history per-item
84 self.__setitem__(k, value[k], at=at, label=label, setHistory=False)
85 except TypeError as e:
86 msg = f"Value {value} is of incorrect type {_typeStr(value)}. Mapping type expected."
87 raise FieldValidationError(self._field, self._config, msg) from e
88 if setHistory:
89 self._history.append((dict(self._dict), at, label))
90

Member Function Documentation

◆ __contains__()

bool lsst.pex.config.dictField.Dict.__contains__ ( self,
Any k )

Definition at line 112 of file dictField.py.

112 def __contains__(self, k: Any) -> bool:
113 return k in self._dict
114

◆ __delitem__()

None lsst.pex.config.dictField.Dict.__delitem__ ( self,
KeyTypeVar k,
Any at = None,
str label = "delitem",
bool setHistory = True )

Definition at line 159 of file dictField.py.

161 ) -> None:
162 if self._config._frozen:
163 raise FieldValidationError(self._field, self._config, "Cannot modify a frozen Config")
164
165 del self._dict[k]
166 if setHistory:
167 if at is None:
168 at = getCallStack()
169 self._history.append((dict(self._dict), at, label))
170

◆ __getitem__()

ItemTypeVar lsst.pex.config.dictField.Dict.__getitem__ ( self,
KeyTypeVar k )

Definition at line 103 of file dictField.py.

103 def __getitem__(self, k: KeyTypeVar) -> ItemTypeVar:
104 return self._dict[k]
105

◆ __iter__()

Iterator[KeyTypeVar] lsst.pex.config.dictField.Dict.__iter__ ( self)

Definition at line 109 of file dictField.py.

109 def __iter__(self) -> Iterator[KeyTypeVar]:
110 return iter(self._dict)
111

◆ __len__()

int lsst.pex.config.dictField.Dict.__len__ ( self)

Definition at line 106 of file dictField.py.

106 def __len__(self) -> int:
107 return len(self._dict)
108

◆ __reduce__()

lsst.pex.config.dictField.Dict.__reduce__ ( self)

Definition at line 189 of file dictField.py.

189 def __reduce__(self):
190 raise UnexpectedProxyUsageError(
191 f"Proxy container for config field {self._field.name} cannot "
192 "be pickled; it should be converted to a built-in container before "
193 "being assigned to other objects or variables."
194 )
195
196

◆ __repr__()

lsst.pex.config.dictField.Dict.__repr__ ( self)

Definition at line 171 of file dictField.py.

171 def __repr__(self):
172 return repr(self._dict)
173

◆ __setattr__()

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

Definition at line 177 of file dictField.py.

177 def __setattr__(self, attr, value, at=None, label="assignment"):
178 if hasattr(getattr(self.__class__, attr, None), "__set__"):
179 # This allows properties to work.
180 object.__setattr__(self, attr, value)
181 elif attr in self.__dict__ or attr in ["_field", "_config_", "_history", "_dict", "__doc__"]:
182 # This allows specific private attributes to work.
183 object.__setattr__(self, attr, value)
184 else:
185 # We throw everything else.
186 msg = f"{_typeStr(self._field)} has no attribute {attr}"
187 raise FieldValidationError(self._field, self._config, msg)
188

◆ __setitem__()

None lsst.pex.config.dictField.Dict.__setitem__ ( self,
KeyTypeVar k,
ItemTypeVar x,
Any at = None,
str label = "setitem",
bool setHistory = True )

Definition at line 115 of file dictField.py.

117 ) -> None:
118 if self._config._frozen:
119 msg = f"Cannot modify a frozen Config. Attempting to set item at key {k!r} to value {x}"
120 raise FieldValidationError(self._field, self._config, msg)
121
122 # validate keytype
123 k = _autocast(k, self._field.keytype)
124 if type(k) is not self._field.keytype:
125 msg = f"Key {k!r} is of type {_typeStr(k)}, expected type {_typeStr(self._field.keytype)}"
126 raise FieldValidationError(self._field, self._config, msg)
127
128 # validate itemtype
129 x = _autocast(x, self._field.itemtype)
130 if self._field.itemtype is None:
131 if type(x) not in self._field.supportedTypes and x is not None:
132 msg = f"Value {x} at key {k!r} is of invalid type {_typeStr(x)}"
133 raise FieldValidationError(self._field, self._config, msg)
134 else:
135 if type(x) is not self._field.itemtype and x is not None:
136 msg = (
137 f"Value {x} at key {k!r} is of incorrect type {_typeStr(x)}. "
138 f"Expected type {_typeStr(self._field.itemtype)}"
139 )
140 raise FieldValidationError(self._field, self._config, msg)
141
142 # validate key using keycheck
143 if self._field.keyCheck is not None and not self._field.keyCheck(k):
144 msg = f"Key {k!r} is not a valid key"
145 raise FieldValidationError(self._field, self._config, msg)
146
147 # validate item using itemcheck
148 if self._field.itemCheck is not None and not self._field.itemCheck(x):
149 msg = f"Item at key {k!r} is not a valid value: {x}"
150 raise FieldValidationError(self._field, self._config, msg)
151
152 if at is None:
153 at = getCallStack()
154
155 self._dict[k] = x
156 if setHistory:
157 self._history.append((dict(self._dict), at, label))
158

◆ __str__()

lsst.pex.config.dictField.Dict.__str__ ( self)

Definition at line 174 of file dictField.py.

174 def __str__(self):
175 return str(self._dict)
176

◆ _config()

Config lsst.pex.config.dictField.Dict._config ( self)
protected

Definition at line 92 of file dictField.py.

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

Member Data Documentation

◆ _config

lsst.pex.config.dictField.Dict._config
protected

Definition at line 87 of file dictField.py.

◆ _config_

lsst.pex.config.dictField.Dict._config_ = weakref.ref(config)
protected

Definition at line 76 of file dictField.py.

◆ _dict

lsst.pex.config.dictField.Dict._dict = {}
protected

Definition at line 77 of file dictField.py.

◆ _field

lsst.pex.config.dictField.Dict._field = field
protected

Definition at line 75 of file dictField.py.

◆ _history

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

Definition at line 78 of file dictField.py.

Property Documentation

◆ history

lsst.pex.config.dictField.Dict.history = property(lambda x: x._history)
static

Definition at line 99 of file dictField.py.


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