Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

passing memoryview slice to struct packing functions #86574

Open
danielhrisca mannequin opened this issue Nov 19, 2020 · 1 comment
Open

passing memoryview slice to struct packing functions #86574

danielhrisca mannequin opened this issue Nov 19, 2020 · 1 comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@danielhrisca
Copy link
Mannequin

danielhrisca mannequin commented Nov 19, 2020

BPO 42408
Nosy @danielhrisca

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2020-11-19.13:41:25.178>
labels = []
title = 'passing memoryview slice to struct packing functions'
updated_at = <Date 2020-11-19.13:41:25.178>
user = 'https://github.com/danielhrisca'

bugs.python.org fields:

activity = <Date 2020-11-19.13:41:25.178>
actor = 'danielhrisca'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = []
creation = <Date 2020-11-19.13:41:25.178>
creator = 'danielhrisca'
dependencies = []
files = []
hgrepos = []
issue_num = 42408
keywords = []
message_count = 1.0
messages = ['381413']
nosy_count = 1.0
nosy_names = ['danielhrisca']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = None
url = 'https://bugs.python.org/issue42408'
versions = []

@danielhrisca
Copy link
Mannequin Author

danielhrisca mannequin commented Nov 19, 2020

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:])

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@iritkatriel iritkatriel added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)
Projects
None yet
Development

No branches or pull requests

1 participant