Author danielhrisca
Recipients danielhrisca
Date 2020-11-19.13:41:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
First I have to apologize if this was discussed before; I've searched the issues and googled the problem but I got nothing obvious.

I'm trying to pass a memoryview slice as argument to struct packing functions to avoid creating intermediate bytes objects

from struct import Struct
s = Struct('<2Q500s').pack_into
buffer = bytearray(7000)
data = bytes(300)
s(buffer, 0, 500, 500, memoryview(data)[4:])

and I get this error:
error: argument for 's' must be a bytes object

Why is it not possible to use memoryviews in this case? 

It is also strange for me that we can use a memoyview as the target buffer, so this works fine:

s(memoryview(buffer)[10:], 0, 500, 500, data[4:])
Date User Action Args
2020-11-19 13:41:25danielhriscasetrecipients: + danielhrisca
2020-11-19 13:41:25danielhriscasetmessageid: <>
2020-11-19 13:41:25danielhriscalinkissue42408 messages
2020-11-19 13:41:25danielhriscacreate