LSST Applications 24.1.6,g063fba187b+56b85ce14a,g0f08755f38+df8a265115,g12f32b3c4e+891a09f10d,g1524ad2192+7a5d7b3fbd,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g28da252d5a+07cb1400be,g2bbee38e9b+ae03bbfc84,g2bc492864f+ae03bbfc84,g3156d2b45e+6e55a43351,g347aa1857d+ae03bbfc84,g35bb328faa+a8ce1bb630,g3a166c0a6a+ae03bbfc84,g3e281a1b8c+c5dd892a6c,g414038480c+6b9177ef31,g41af890bb2+8f257c4c0b,g781aacb6e4+a8ce1bb630,g7af13505b9+7137b3b17d,g80478fca09+6df6903293,g82479be7b0+091ce1d07f,g858d7b2824+df8a265115,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,g9726552aa6+414189b318,ga5288a1d22+4a2bca08d7,gacef1a1666+c9a8ff65f4,gb58c049af0+d64f4d3760,gbcfae0f0a0+de1d42d831,gc28159a63d+ae03bbfc84,gcf0d15dbbd+72117bf34e,gda6a2b7d83+72117bf34e,gdaeeff99f8+1711a396fd,ge500cccec5+c8c9c9af63,ge79ae78c31+ae03bbfc84,gf0baf85859+c1f95f4921,gfa517265be+df8a265115,gfa999e8aa5+17cd334064,gfb92a5be7c+df8a265115
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.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
 
 _config_
 
 _dict
 
 _history
 
 _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 )

Reimplemented in lsst.pex.config.configDictField.ConfigDict, lsst.pex.config.configDictField.ConfigDictField, and lsst.pex.config.dictField.DictField.

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:
86 msg = f"Value {value} is of incorrect type {_typeStr(value)}. Mapping type expected."
87 raise FieldValidationError(self._field, self._config, msg)
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 )

Reimplemented in lsst.pex.config.configDictField.ConfigDict.

Definition at line 154 of file dictField.py.

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

◆ __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 184 of file dictField.py.

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

◆ __repr__()

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

Definition at line 166 of file dictField.py.

166 def __repr__(self):
167 return repr(self._dict)
168

◆ __setattr__()

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

Definition at line 172 of file dictField.py.

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

◆ __setitem__()

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

Reimplemented in lsst.pex.config.configDictField.ConfigDict.

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 item using itemcheck
143 if self._field.itemCheck is not None and not self._field.itemCheck(x):
144 msg = f"Item at key {k!r} is not a valid value: {x}"
145 raise FieldValidationError(self._field, self._config, msg)
146
147 if at is None:
148 at = getCallStack()
149
150 self._dict[k] = x
151 if setHistory:
152 self._history.append((dict(self._dict), at, label))
153

◆ __str__()

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

Definition at line 169 of file dictField.py.

169 def __str__(self):
170 return str(self._dict)
171

◆ _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_
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
protected

Definition at line 75 of file dictField.py.

◆ _history

lsst.pex.config.dictField.Dict._history
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: