MCPcopy Index your code
hub / github.com/python/cpython / get_or_create_nest

Method get_or_create_nest

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

Source from the content-addressed store, hash-verified

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

no outgoing calls

Tested by

no test coverage detected