Convert a SON document to a normal Python dictionary instance. This is trickier than just *dict(...)* because it needs to be recursive.
(self)
| 198 | return len(self.__keys) |
| 199 | |
| 200 | def to_dict(self) -> dict[_Key, _Value]: |
| 201 | """Convert a SON document to a normal Python dictionary instance. |
| 202 | |
| 203 | This is trickier than just *dict(...)* because it needs to be |
| 204 | recursive. |
| 205 | """ |
| 206 | |
| 207 | def transform_value(value: Any) -> Any: |
| 208 | if isinstance(value, list): |
| 209 | return [transform_value(v) for v in value] |
| 210 | elif isinstance(value, _Mapping): |
| 211 | return {k: transform_value(v) for k, v in value.items()} |
| 212 | else: |
| 213 | return value |
| 214 | |
| 215 | return cast("dict[_Key, _Value]", transform_value(dict(self))) |
| 216 | |
| 217 | def __deepcopy__(self, memo: dict[int, SON[_Key, _Value]]) -> SON[_Key, _Value]: |
| 218 | out: SON[_Key, _Value] = SON() |
no outgoing calls