-
Type: New Feature
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
In PYTHON-1528, salty-horse suggested adding support for encoding sets, ranges, frozenset, and various other built-in (and iterable) objects by default. We decided that doing so could mask bugs because BSON cannot preserve these objects when decoding.
Applications that want to encode these types can use the TypeEncoder API added in PYTHON-1476 to convert these types to a list. This approach allows sets to be encoded as a bson array but it has the unfortunate side effect of temporarily inflating the entire set/iterable to a single python list.
It would be more efficient to iterate over the set while encoding it. One way we could accomplish this is by adding a new bson module type bson.Iterable to wrap the object. Something like this:
>>> from bson import BSON, Iterable >>> >>> bson_bytes = BSON.encode({'ints': Iterable(range(5))}) >>> bson_bytes.decode() {'ints': [0, 1, 2, 3, 4]}
- related to
-
PYTHON-1168 Support arbitrary sequence types for BSON array
- Closed
-
PYTHON-1528 BSON should be able to encode range, set, frozenset, and dictionary view objects
- Closed