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

Method __getitem__

box/box.py:98–110  ·  view source on GitHub ↗
(self, item, _ignore_default=False)

Source from the content-addressed store, hash-verified

96 """
97
98 def __getitem__(self, item, _ignore_default=False):
99 if isinstance(item, str) and item.startswith("["):
100 list_pos = _tuple_pos_re.match(item)
101 if list_pos is None:
102 raise BoxTypeError(f"Invalid list index: {item!r}")
103 value = tuple.__getitem__(self, int(list_pos.group(1)))
104 children = item[list_pos.end() :].lstrip(".")
105 if not children:
106 return value
107 if _ignore_default and isinstance(value, (Box, box.BoxList, _BoxTuple)):
108 return value.__getitem__(children, _ignore_default=True)
109 return value[children]
110 return tuple.__getitem__(self, item)
111
112 def _comment_store(self, create: bool = True) -> Any:
113 store = self.__dict__.get("_box_comments")

Callers

nothing calls this directly

Calls 2

BoxTypeErrorClass · 0.90
__getitem__Method · 0.45

Tested by

no test coverage detected