MCPcopy Create free account
hub / github.com/cdgriffith/Box / __setitem__

Method __setitem__

box/box.py:663–687  ·  view source on GitHub ↗
(self, key, value)

Source from the content-addressed store, hash-verified

661 return value
662
663 def __setitem__(self, key, value):
664 if key != "_box_config" and self._box_config["frozen_box"] and self._box_config["__created"]:
665 raise BoxError("Box is frozen")
666 if self.__process_dotted_key(key):
667 first_item, children = _parse_box_dots(self, key, setting=True)
668 if first_item in self.keys():
669 if hasattr(self[first_item], "__setitem__"):
670 return self[first_item].__setitem__(children, value)
671 elif self._box_config["default_box"]:
672 if children[0] == "[":
673 super().__setitem__(first_item, box.BoxList(**self.__box_config(extra_namespace=first_item)))
674 else:
675 super().__setitem__(
676 first_item, self._box_config["box_class"](**self.__box_config(extra_namespace=first_item))
677 )
678 return self[first_item].__setitem__(children, value)
679 else:
680 raise BoxKeyError(f"'{self.__class__}' object has no attribute {first_item}")
681 value = self.__recast(key, value)
682 if key not in self.keys() and self._box_config["camel_killer_box"]:
683 if self._box_config["camel_killer_box"] and isinstance(key, str):
684 key = _camel_killer(key)
685 if self._box_config["conversion_box"] and self._box_config["box_duplicates"] != "ignore":
686 self._conversion_checks(key)
687 self.__convert_and_store(key, value)
688
689 def __setattr__(self, key, value):
690 if key == "_box_config":

Callers 5

__init__Method · 0.95
__setattr__Method · 0.95
convert_and_setMethod · 0.95
__get_defaultMethod · 0.45
__convert_and_storeMethod · 0.45

Calls 10

__process_dotted_keyMethod · 0.95
keysMethod · 0.95
__box_configMethod · 0.95
__recastMethod · 0.95
_conversion_checksMethod · 0.95
__convert_and_storeMethod · 0.95
BoxErrorClass · 0.90
BoxKeyErrorClass · 0.90
_parse_box_dotsFunction · 0.85
_camel_killerFunction · 0.85

Tested by

no test coverage detected