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

Method __setitem__

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

Source from the content-addressed store, hash-verified

947 return state
948
949 def __setitem__(self, key, value):
950 if key != "_box_config" and self._box_config["frozen_box"] and self._box_config["__created"]:
951 raise BoxError("Box is frozen")
952 if self.__process_dotted_key(key):
953 first_item, children = _parse_box_dots(self, key)
954 first_item = self.__dots_int_key(first_item)
955 if first_item in self.keys():
956 child = self[first_item]
957 if isinstance(child, Box):
958 children = child.__dots_int_key(children)
959 if hasattr(child, "__setitem__"):
960 return child.__setitem__(children, value)
961 elif self._box_config["default_box"]:
962 self._flush_pending_parent()
963 if children.startswith("["):
964 super().__setitem__(first_item, box.BoxList(**self.__box_config(extra_namespace=first_item)))
965 else:
966 super().__setitem__(
967 first_item, self._box_config["box_class"](**self.__box_config(extra_namespace=first_item))
968 )
969 return self[first_item].__setitem__(children, value)
970 else:
971 raise BoxKeyError(f"'{self.__class__}' object has no attribute {first_item}")
972 value = self.__recast(key, value)
973 if key not in self.keys() and self.__camel_destructive():
974 if isinstance(key, str):
975 key = _camel_killer(key)
976 if self._box_config["conversion_box"] and self._box_config["box_duplicates"] != "ignore":
977 self._conversion_checks(key)
978 self.__convert_and_store(key, value)
979
980 def __setattr__(self, key, value):
981 if key == "_box_config":

Callers 8

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

Calls 13

__process_dotted_keyMethod · 0.95
__dots_int_keyMethod · 0.95
keysMethod · 0.95
_flush_pending_parentMethod · 0.95
__box_configMethod · 0.95
__recastMethod · 0.95
__camel_destructiveMethod · 0.95
_conversion_checksMethod · 0.95
__convert_and_storeMethod · 0.95
BoxErrorClass · 0.90
BoxKeyErrorClass · 0.90
_parse_box_dotsFunction · 0.85