| 264 | |
| 265 | |
| 266 | class NestedDict: |
| 267 | def __init__(self) -> None: |
| 268 | # The parsed content of the TOML document |
| 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]) |
| 290 | last_key = key[-1] |
| 291 | if last_key in cont: |
| 292 | list_ = cont[last_key] |
| 293 | if not isinstance(list_, list): |
| 294 | raise KeyError("An object other than list found behind this key") |
| 295 | list_.append({}) |
| 296 | else: |
| 297 | cont[last_key] = [{}] |
| 298 | |
| 299 | |
| 300 | class Output: |
no outgoing calls
no test coverage detected
searching dependent graphs…