MCPcopy Index your code
hub / github.com/RustPython/RustPython / get_or_create_nest

Method get_or_create_nest

Lib/tomllib/_parser.py:270–285  ·  view source on GitHub ↗
(
        self,
        key: Key,
        *,
        access_lists: bool = True,
    )

Source from the content-addressed store, hash-verified

268 self.dict: dict[str, Any] = {}
269
270 def get_or_create_nest(
271 self,
272 key: Key,
273 *,
274 access_lists: bool = True,
275 ) -> dict[str, Any]:
276 cont: Any = self.dict
277 for k in key:
278 if k not in cont:
279 cont[k] = {}
280 cont = cont[k]
281 if access_lists and isinstance(cont, list):
282 cont = cont[-1]
283 if not isinstance(cont, dict):
284 raise KeyError("There is no nest behind this key")
285 return cont # type: ignore[no-any-return]
286
287 def append_nest_to_list(self, key: Key) -> None:
288 cont = self.get_or_create_nest(key[:-1])

Callers 4

append_nest_to_listMethod · 0.95
parse_inline_tableFunction · 0.95
create_dict_ruleFunction · 0.80
key_value_ruleFunction · 0.80

Calls 1

isinstanceFunction · 0.85

Tested by

no test coverage detected