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

py: memoryview: implement memoryview.cast if CPYTHON_COMPAT #4231

Merged
merged 3 commits into from
Feb 21, 2021

Conversation

jepler
Copy link
Member

@jepler jepler commented Feb 20, 2021

This allows the following Python3-compatible code to work:

>>> b = bytearray([0] * 4)
>>> memoryview(b).cast('H')[0] = 0xffff
>>> b
bytearray(b'\xff\xff\x00\x00')

At one point I thought I might need this for my neopixel bit-twiddling, but I don't specifically need it right now. However, I wanted to post it up as a PR rather than just forgetting about it.

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a brief test, and it did what I expected. I had no idea memoryview.cast() existed.

@dhalbert dhalbert merged commit 2830984 into adafruit:main Feb 21, 2021
@jepler jepler deleted the memoryview-cast branch November 3, 2021 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants