diff options
| author | David Lechner <david@pybricks.com> | 2022-06-10 12:28:56 -0500 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2022-06-21 00:44:49 +1000 |
| commit | a565811f23c675ccbeed636c065828cdaf5fa96a (patch) | |
| tree | 947cde359e85a6c97232b9df5cb6d2dcecd773f2 /tests | |
| parent | c118b5d0e428094bd64a003d97b078c2d7c7500d (diff) | |
extmod/modbtree: Use buffer protocol for keys/values.
This changes the btree implementation to use the buffer protocol for
reading key/values in all methods. `str` and `bytes` objects are not the
only bytes-like objects that could be used.
Documentation and tests are also updated.
Addresses issue #8748.
Signed-off-by: David Lechner <david@pybricks.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/extmod/btree1.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/tests/extmod/btree1.py b/tests/extmod/btree1.py index 1f4853eaa..876bce4f8 100644 --- a/tests/extmod/btree1.py +++ b/tests/extmod/btree1.py @@ -10,10 +10,13 @@ except ImportError: f = uio.BytesIO() db = btree.open(f, pagesize=512) +mv = memoryview(b"bar1foo1") + db[b"foo3"] = b"bar3" db[b"foo1"] = b"bar1" -db[b"foo2"] = b"bar2" -db[b"bar1"] = b"foo1" +# any type that implements buffer protocol works for key and value +db["foo2"] = "bar2" +db[mv[:4]] = mv[4:] dbstr = str(db) print(dbstr[:7], dbstr[-1:]) |
