gh-104533: Add a dataclass-like decorator for ctypes structures#153781
Open
ZeroIntensity wants to merge 10 commits into
Open
gh-104533: Add a dataclass-like decorator for ctypes structures#153781ZeroIntensity wants to merge 10 commits into
ctypes structures#153781ZeroIntensity wants to merge 10 commits into
Conversation
Documentation build overview
|
johnslavik
reviewed
Jul 15, 2026
Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
johnslavik
approved these changes
Jul 16, 2026
Comment on lines
+561
to
+576
| def struct(class_or_none=None, /, *, align=None, layout=None, endian='native', pack=None): | ||
| process_the_struct = functools.partial( | ||
| _process_struct, | ||
| align=align, | ||
| layout=layout, | ||
| endian=endian, | ||
| pack=pack | ||
| ) | ||
|
|
||
| if class_or_none is None: | ||
| def inner(klass): | ||
| return process_the_struct(klass) | ||
|
|
||
| return inner | ||
|
|
||
| return process_the_struct(class_or_none) |
Member
There was a problem hiding this comment.
I meant it like this:
Suggested change
| def struct(class_or_none=None, /, *, align=None, layout=None, endian='native', pack=None): | |
| process_the_struct = functools.partial( | |
| _process_struct, | |
| align=align, | |
| layout=layout, | |
| endian=endian, | |
| pack=pack | |
| ) | |
| if class_or_none is None: | |
| def inner(klass): | |
| return process_the_struct(klass) | |
| return inner | |
| return process_the_struct(class_or_none) | |
| def struct(class_or_none=None, /, *, align=None, layout=None, endian='native', pack=None): | |
| if class_or_none is None: | |
| return functools.partial( | |
| struct, | |
| align=align, | |
| layout=layout, | |
| endian=endian, | |
| pack=pack, | |
| ) | |
| return process_the_struct(class_or_none) |
That's how decorators of this fashion are usually made.
Feel free to ignore.
Member
Author
There was a problem hiding this comment.
process_the_struct isn't defined here; what are you trying to show?
Comment on lines
+3164
to
+3165
| .. decorator:: struct(*, align=None, layout, endian='native', pack=None) | ||
| :module: ctypes.util |
Member
There was a problem hiding this comment.
Consider adding a collation: old syntax vs. new syntax.
Member
Author
There was a problem hiding this comment.
I don't think that's necessary -- the examples for Structure are right above.
merwok
reviewed
Jul 16, 2026
Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.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.
Uh oh!
There was an error while loading. Please reload this page.