This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients Yury.Selivanov, belopolsky, eryksun, methane, ncoghlan, serhiy.storchaka, vstinner, xiang.zhang, yselivanov
Date 2017-01-08.04:35:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1483850121.73.0.247432416825.issue29178@psf.upfronthosting.co.za>
In-reply-to
Content
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):
        ...
History
Date User Action Args
2017-01-08 04:35:21ncoghlansetrecipients: + ncoghlan, belopolsky, vstinner, methane, Yury.Selivanov, serhiy.storchaka, yselivanov, eryksun, xiang.zhang
2017-01-08 04:35:21ncoghlansetmessageid: <1483850121.73.0.247432416825.issue29178@psf.upfronthosting.co.za>
2017-01-08 04:35:21ncoghlanlinkissue29178 messages
2017-01-08 04:35:21ncoghlancreate