MCPcopy Create free account
hub / github.com/bundesAPI/smard-api / get

Method get

python-client/deutschland/smard/model_utils.py:622–651  ·  view source on GitHub ↗

returns the value of an attribute or some default value if the attribute was not set

(self, name, default=None)

Source from the content-addressed store, hash-verified

620 __unset_attribute_value__ = object()
621
622 def get(self, name, default=None):
623 """returns the value of an attribute or some default value if the attribute was not set"""
624 if name in self.required_properties:
625 return self.__dict__[name]
626
627 # get the attribute from the correct instance
628 model_instances = self._var_name_to_model_instances.get(name)
629 values = []
630 # A composed model stores self and child (oneof/anyOf/allOf) models under
631 # self._var_name_to_model_instances.
632 # Any property must exist in self and all model instances
633 # The value stored in all model instances must be the same
634 if model_instances:
635 for model_instance in model_instances:
636 if name in model_instance._data_store:
637 v = model_instance._data_store[name]
638 if v not in values:
639 values.append(v)
640 len_values = len(values)
641 if len_values == 0:
642 return default
643 elif len_values == 1:
644 return values[0]
645 elif len_values > 1:
646 raise ApiValueError(
647 "Values stored for property {0} in {1} differ when looking "
648 "at self and self's composed instances. All values must be "
649 "the same".format(name, type(self).__name__),
650 [e for e in [self._path_to_item, name] if e],
651 )
652
653 def __getitem__(self, name):
654 """get the value of an attribute using square-bracket notation: `instance[attr]`"""

Callers 1

__getitem__Method · 0.95

Calls 2

ApiValueErrorClass · 0.90
getMethod · 0.45

Tested by

no test coverage detected