MCPcopy Create free account
hub / github.com/ahalev/python-microgrid / set_attrs

Method set_attrs

src/pymgrid/modules/module_container.py:241–273  ·  view source on GitHub ↗

Set the value of an attribute in all modules containing that attribute. Does nothing in modules not already containing the attribute. You may either pass attr_dict, a dict of attributes, or pass attributes as keyword arguments. Parameters ----------

(self, attr_dict=None, **attrs)

Source from the content-addressed store, hash-verified

239 return val
240
241 def set_attrs(self, attr_dict=None, **attrs):
242 """
243 Set the value of an attribute in all modules containing that attribute.
244
245 Does nothing in modules not already containing the attribute.
246
247 You may either pass attr_dict, a dict of attributes, or pass attributes as keyword arguments.
248
249 Parameters
250 ----------
251 attr_dict : dict
252 Key-value pairs or attributes to set. Keys are attribute names values are the values
253 to set attribute to.
254 attrs : dict
255 Key-value pairs or attributes to set. Keys are attribute names values are the values
256 to set attribute to.
257
258 Raises
259 ------
260 AttributeError
261 If no module has the attribute.
262
263 """
264 if attr_dict:
265 if attrs:
266 raise ValueError('Both attr_dict and keyword arguments were passed.')
267 elif attrs:
268 attr_dict = attrs
269 else:
270 raise ValueError('Missing attributes to set.')
271
272 for attr_name, value in attr_dict.items():
273 self._set_attr(attr_name, value)
274
275 def _set_attr(self, attr_name, value):
276 set_at_least_one = False

Callers 1

set_module_attrsMethod · 0.80

Calls 1

_set_attrMethod · 0.95

Tested by

no test coverage detected