Accept memoryview in setter/getter type annotations#647
Merged
Conversation
The setter functions already worked with memoryview at runtime (using direct struct.pack() slice assignment), but the type annotations only accepted bytearray. This caused mypy errors when passing memoryview objects from ctypes buffers. - Add Buffer type alias (Union[bytearray, memoryview]) to setters and getters - Update all function signatures to accept Buffer - Fix .decode() calls in getters to use bytes() for memoryview compat - Add 17 memoryview compatibility tests Credit: LuTiFlekSSer for identifying the memoryview compatibility issue. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Buffer = Union[bytearray, memoryview]type alias to setters and gettersbytearrayandmemoryview.decode()calls inget_wchar/get_wstringto usebytes()conversion for memoryview compatibilityThe setter functions already worked at runtime with
memoryview(they use directstruct.pack()slice assignment), but the type annotations only acceptedbytearray, causing mypy errors when passing memoryview objects from ctypes buffers. This is a common use case with theServerclass.Credit to LuTiFlekSSer for identifying the memoryview compatibility issue in their fork.
Test plan
🤖 Generated with Claude Code