Message284958
The complexity you're hitting here is the main reason I'm a fan of creating a dedicated library for dealing with these problems, rather than trying to handle them directly on the builtins.
Given a bufferlib module, for example, you could have a higher level API like:
def snapshot(source, *, result_type=bytes):
...
That handled any source object that supported the buffer protocol, and any target type that accepted a memoryview instance as input to the constructor.
# Default bytes snapshot
data = snapshot(original)
# Mutable snapshot without copying and promptly releasing the view
data = snapshot(original, result_type=bytearray)
The start/stop/step or length+offset question could be handled at that level by allowing both, but also offering lower level APIs with less argument processing overhead:
def snapshot_slice(source, start, stop, step=1, *, result_type=bytes):
...
def snapshot_at(source, *, offset=0, count=None, result_type=bytes):
... |
|
Date |
User |
Action |
Args |
2017-01-08 04:35:21 | ncoghlan | set | recipients:
+ ncoghlan, belopolsky, vstinner, methane, Yury.Selivanov, serhiy.storchaka, yselivanov, eryksun, xiang.zhang |
2017-01-08 04:35:21 | ncoghlan | set | messageid: <1483850121.73.0.247432416825.issue29178@psf.upfronthosting.co.za> |
2017-01-08 04:35:21 | ncoghlan | link | issue29178 messages |
2017-01-08 04:35:21 | ncoghlan | create | |
|