MCPcopy Create free account
hub / github.com/mongodb/mongo-python-driver / to_dict

Method to_dict

bson/son.py:200–215  ·  view source on GitHub ↗

Convert a SON document to a normal Python dictionary instance. This is trickier than just *dict(...)* because it needs to be recursive.

(self)

Source from the content-addressed store, hash-verified

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()

Callers 3

test_to_dictMethod · 0.95
test_clearsMethod · 0.95
__eq__Method · 0.95

Calls

no outgoing calls

Tested by 2

test_to_dictMethod · 0.76
test_clearsMethod · 0.76